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.

http module-attribute

http = HTTPClientSettings.parse_obj({})

HTTP Client 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.

worker module-attribute

worker = WorkerSettings.parse_obj({})

Worker 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.

CHECK_DB_READY class-attribute

CHECK_DB_READY: bool = True

Check for database readiness on startup.

CHECK_REDIS_READY class-attribute

CHECK_REDIS_READY: bool = True

Check for redis readiness on startup.

DEBUG class-attribute

DEBUG: bool = False

Run Starlite with debug=True.

ENVIRONMENT class-attribute

ENVIRONMENT: str = 'prod'

'dev', 'prod', etc.

LOCAL_ENVIRONMENT_NAME class-attribute

LOCAL_ENVIRONMENT_NAME: str = 'local'

Value of ENVIRONMENT used to determine if running in local development mode.

This should be the value of ENVIRONMENT in your local .env file.

NAME class-attribute

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

Application name.

TEST_ENVIRONMENT_NAME class-attribute

TEST_ENVIRONMENT_NAME: str = 'test'

Value of ENVIRONMENT used to determine if running tests.

This should be the value of ENVIRONMENT in test.env.

slug property

slug: str

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.

HTTPClientSettings

Bases: BaseSettings

HTTP Client configurations.

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",
    "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 SQLAlchemy 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 = 20

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 | None = None

Turn on hot reloading.

RELOAD_DIRS class-attribute

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

Directories to watch for reloading.

WorkerSettings

Bases: BaseSettings

Global SAQ Job configuration.

JOB_HEARTBEAT class-attribute

JOB_HEARTBEAT: int = 0

Max time a job can survive without emitting a heartbeat. 0 to disable.

job.update() will trigger a heartbeat.

JOB_RETRIES class-attribute

JOB_RETRIES: int = 10

Max attempts for any job.

JOB_RETRY_BACKOFF class-attribute

JOB_RETRY_BACKOFF: bool | float = 60

If true, use exponential backoff for retry delays.

  • The first retry will have whatever retry_delay is.
  • The second retry will have retry_delay2. The third retry will have retry_delay4. And so on.
  • This always includes jitter, where the final retry delay is a random number between 0 and the calculated retry delay.
  • If retry_backoff is set to a number, that number is the maximum retry delay, in seconds."

JOB_RETRY_DELAY class-attribute

JOB_RETRY_DELAY: float = 1.0

Seconds to delay before retrying a job.

JOB_TIMEOUT class-attribute

JOB_TIMEOUT: int = 10

Max time a job can run for, in seconds.

Set to 0 for no timeout.

JOB_TTL class-attribute

JOB_TTL: int = 600

Lifetime of available job information, in seconds.

0: indefinite -1: disabled (no info retained)