Skip to content

settings

All configuration via environment.

Take note of the environment variable prefixes required for each settings class, except AppSettings.

api module-attribute

api = APISettings.parse_obj({})

Api settings.

app module-attribute

app = AppSettings.parse_obj({})

App settings.

db module-attribute

db = DatabaseSettings.parse_obj({})

Database settings.

log module-attribute

log = LogSettings.parse_obj({})

Log settings.

openapi module-attribute

openapi = OpenAPISettings.parse_obj({})

Openapi settings.

redis module-attribute

redis = RedisSettings.parse_obj({})

Redis settings.

sentry module-attribute

sentry = SentrySettings.parse_obj({})

Sentry settings.

server module-attribute

server = ServerSettings.parse_obj({})

Server settings.

APISettings

Bases: BaseSettings

API specific configuration.

CACHE_EXPIRATION class-attribute

CACHE_EXPIRATION: int = 60

Default cache key expiration in seconds.

DB_SESSION_DEPENDENCY_KEY class-attribute

DB_SESSION_DEPENDENCY_KEY: str = 'db_session'

Parameter name for SQLAlchemy session dependency injection.

DEFAULT_PAGINATION_LIMIT class-attribute

DEFAULT_PAGINATION_LIMIT: int = 100

Max records received for collection routes.

DTO_INFO_KEY class-attribute

DTO_INFO_KEY: str = 'dto'

Key used for DTO field config in SQLAlchemy info dict.

HEALTH_PATH class-attribute

HEALTH_PATH: str = '/health'

Route that the health check is served under.

AppSettings

Bases: BaseSettings

Generic application settings.

These settings are returned as json by the healthcheck endpoint, so do not include any sensitive values here, or if you do ensure to exclude them from serialization in the Config object.

BUILD_NUMBER class-attribute

BUILD_NUMBER: str = ''

Identifier for CI build.

DEBUG class-attribute

DEBUG: bool = False

Run Starlite with debug=True.

ENVIRONMENT class-attribute

ENVIRONMENT: str = 'prod'

'dev', 'prod', etc.

NAME class-attribute

NAME: str = 'my-starlite-saqlalchemy-app'

Application name.

slug property

slug()

Return a slugified name.

Returns:

Type Description
str

self.NAME, all lowercase and hyphens instead of spaces.

DatabaseSettings

Bases: BaseSettings

Configures the database for the application.

ECHO class-attribute

ECHO: bool = False

Enable SQLAlchemy engine logs.

ECHO_POOL class-attribute

ECHO_POOL: bool | Literal['debug'] = False

Enable SQLAlchemy connection pool logs.

POOL_DISABLE class-attribute

POOL_DISABLE: bool = False

Disable SQLAlchemy pooling, same as setting pool to NullPool.

POOL_MAX_OVERFLOW class-attribute

POOL_MAX_OVERFLOW: int = 10

POOL_SIZE class-attribute

POOL_SIZE: int = 5

See pool_size.

POOL_TIMEOUT class-attribute

POOL_TIMEOUT: int = 30

See timeout.

LogSettings

Bases: BaseSettings

Logging config for the application.

EXCLUDE_PATHS class-attribute

EXCLUDE_PATHS: str = '\\A(?!x)x'

Regex to exclude paths from logging.

HTTP_EVENT class-attribute

HTTP_EVENT: str = 'HTTP'

Log event name for logs from Starlite handlers.

INCLUDE_COMPRESSED_BODY class-attribute

INCLUDE_COMPRESSED_BODY: bool = False

Include 'body' of compressed responses in log output.

JOB_FIELDS class-attribute

JOB_FIELDS: list[str] = [
    "function",
    "kwargs",
    "key",
    "scheduled",
    "attempts",
    "completed",
    "queued",
    "started",
    "result",
    "error",
]

Attributes of the SAQ Job to be logged.

LEVEL class-attribute

LEVEL: int = 20

Stdlib log levels. Only emit logs at this level, or higher.

OBFUSCATE_COOKIES class-attribute

OBFUSCATE_COOKIES: set[str] = {'session'}

Request cookie keys to obfuscate.

OBFUSCATE_HEADERS class-attribute

OBFUSCATE_HEADERS: set[str] = {'Authorization', 'X-API-KEY'}

Request header keys to obfuscate.

REQUEST_FIELDS class-attribute

REQUEST_FIELDS: list[RequestExtractorField] = [
    "path",
    "method",
    "content_type",
    "headers",
    "cookies",
    "query",
    "path_params",
    "body",
]

Attributes of the Request to be logged.

RESPONSE_FIELDS class-attribute

RESPONSE_FIELDS: list[ResponseExtractorField] = ['status_code', 'cookies', 'headers', 'body']

Attributes of the Response to be logged.

SAQ_LEVEL class-attribute

SAQ_LEVEL: int = 30

Level to log SAQ logs.

SQLALCHEMY_LEVEL class-attribute

SQLALCHEMY_LEVEL: int = 30

Level to log SAQ logs.

UVICORN_ACCESS_LEVEL class-attribute

UVICORN_ACCESS_LEVEL: int = 30

Level to log uvicorn access logs.

UVICORN_ERROR_LEVEL class-attribute

UVICORN_ERROR_LEVEL: int = 30

Level to log uvicorn error logs.

WORKER_EVENT class-attribute

WORKER_EVENT: str = 'Worker'

Log event name for logs from SAQ worker.

OpenAPISettings

Bases: BaseSettings

Configures OpenAPI for the application.

CONTACT_EMAIL class-attribute

CONTACT_EMAIL: str = 'peter.github@proton.me'

Email for contact on document.

CONTACT_NAME class-attribute

CONTACT_NAME: str = 'Peter'

Name of contact on document.

TITLE class-attribute

TITLE: str | None = 'My Starlite-SAQAlchemy App'

Document title.

VERSION class-attribute

VERSION: str = 'v1.0'

Document version.

RedisSettings

Bases: BaseSettings

Redis settings for the application.

URL class-attribute

URL: AnyUrl = parse_obj_as(AnyUrl, 'redis://localhost:6379/0')

A Redis connection URL.

SentrySettings

Bases: BaseSettings

Configures sentry for the application.

DSN class-attribute

DSN: str = ''

The sentry DSN. Set as empty string to disable sentry reporting.

TRACES_SAMPLE_RATE class-attribute

TRACES_SAMPLE_RATE: float = 0.0001

% of requests traced by sentry, 0.0 means none, 1.0 means all.

ServerSettings

Bases: BaseSettings

Server configurations.

APP_LOC class-attribute

APP_LOC: str = 'app.main:create_app'

Path to app executable, or factory.

APP_LOC_IS_FACTORY class-attribute

APP_LOC_IS_FACTORY: bool = True

Indicate if APP_LOC points to an executable or factory.

HOST class-attribute

HOST: str = 'localhost'

Server network host.

KEEPALIVE class-attribute

KEEPALIVE: int = 65

Seconds to hold connections open (65 is > AWS lb idle timeout).

PORT class-attribute

PORT: int = 8000

Server port.

RELOAD class-attribute

RELOAD: bool = False

Turn on hot reloading.

RELOAD_DIRS class-attribute

RELOAD_DIRS: list[str] = ['src/']

Directories to watch for reloading.