Base Settings Models

Defines all application settings models (dataclasses) and the central function for loading configuration.

Configuration Loader

get_settings() Settings[source]

Load and cache application configuration.

Settings Container (Settings)

class Settings(app: app.config.base.AppSettings = <factory>, log: app.config.base.LogSettings = <factory>, db: app.config.base.DatabaseSettings = <factory>, jwt: app.config.base.JWTSettings = <factory>, redis: app.config.base.RedisSettings = <factory>)[source]

Bases: object

Container class holding all application configuration settings.

app

Application-level settings.

Type:

AppSettings

log

Logging configuration.

Type:

LogSettings

db

Database connection and pool settings.

Type:

DatabaseSettings

jwt

JWT token configuration.

Type:

JWTSettings

redis

Redis client and connection settings.

Type:

RedisSettings

Application Settings (AppSettings)

class AppSettings(DEBUG: bool = <factory>, NAME: str = 'IronTrack', ENVIRONMENT: str = <factory>, API_V1_URL_PREFIX: str = '/api/v1', CDN_IMAGES_DEFAULT_URL: str = <factory>)[source]

Bases: object

Application configuration.

DEBUG: bool

Whether to run the FastAPI application in debug mode.

NAME: str = 'IronTrack'

Application name.

ENVIRONMENT: str

The application execution environment (e.g., ‘dev’, ‘prod’).

API_V1_URL_PREFIX: str = '/api/v1'

The default URL prefix for API Version routes.

CDN_IMAGES_DEFAULT_URL: str

The default base URL for CDN-hosted exercise images.

Logger Settings (LogSettings)

class LogSettings(LEVEL: int = <factory>, STRUCTLOG_LEVEL: int = 20, ASGI_ACCESS_LEVEL: int = <factory>, ASGI_ERROR_LEVEL: int = <factory>, MIDDLEWARE_LOG_LEVEL: int = 20, SQLALCHEMY_LEVEL: int = <factory>)[source]

Bases: object

Logger configuration.

LEVEL: int

Standard library log level for the root logger.

STRUCTLOG_LEVEL: int = 20

Fixed structlog filtering level.

Must be 20 (INFO) to ensure middleware logs are not dropped before reaching the standard logging library.

ASGI_ACCESS_LEVEL: int

Logging level for the server’s internal access logs.

ASGI_ERROR_LEVEL: int

Logging level for the server’s runtime events and errors.

MIDDLEWARE_LOG_LEVEL: int = 20

Fixed logging level for the ASGI access middleware.

Must be 20 (INFO). Higher levels disable tracking of important requests needed for traffic monitoring and analysis.

SQLALCHEMY_LEVEL: int

SQLAlchemy logs level.

property final_formatter: str

The name of the logging formatter based on the current environment.

Returns:

‘plain_console’ for development, ‘json_console’ otherwise.

Return type:

str

Database Settings (DatabaseSettings)

class DatabaseSettings(POSTGRES_HOST: str = <factory>, POSTGRES_PORT: int = <factory>, POSTGRES_USER: str = <factory>, POSTGRES_PASSWORD: str = <factory>, POSTGRES_DB: str = <factory>, URL: str | None = <factory>, ECHO: bool = <factory>, ECHO_POOL: bool = <factory>, POOL_MAX_OVERFLOW: int = <factory>, POOL_SIZE: int = <factory>, POOL_TIMEOUT: int = <factory>, POOL_RECYCLE: int = <factory>, POOL_PRE_PING: bool = <factory>, POOL_DISABLED: bool = <factory>, MIGRATION_CONFIG: str = <factory>, MIGRATION_PATH: str = <factory>, MIGRATION_DDL_VERSION_TABLE: str = 'ddl_version', FIXTURE_PATH: str = <factory>, PGBOUNCER_ENABLED: bool = <factory>)[source]

Bases: object

Database configuration.

POSTGRES_HOST: str

The PostgreSQL server hostname.

POSTGRES_PORT: int

The PostgreSQL server port number.

POSTGRES_USER: str

The PostgreSQL database username.

POSTGRES_PASSWORD: str

The PostgreSQL database password.

POSTGRES_DB: str

The PostgreSQL database name.

URL: str | None

The full, pre-configured database connection URL.

Type:

Optional

ECHO: bool

Enable SQLAlchemy engine logs.

ECHO_POOL: bool

Enable SQLAlchemy connection pool logs.

POOL_MAX_OVERFLOW: int

Max overflow for SQLAlchemy connection pool

POOL_SIZE: int

Pool size for SQLAlchemy connection pool

POOL_TIMEOUT: int

Time in seconds for timing connections out of the connection pool.

POOL_RECYCLE: int

Amount of time to wait before recycling connections.

POOL_PRE_PING: bool

Optionally ping database before fetching a session from the connection pool.

POOL_DISABLED: bool

Disable SQLAlchemy pool configuration.

MIGRATION_CONFIG: str

The path to the alembic.ini configuration file.

MIGRATION_PATH: str

The path to the alembic database migrations.

MIGRATION_DDL_VERSION_TABLE: str = 'ddl_version'

The name to use for the alembic versions table name.

FIXTURE_PATH: str

The path to JSON fixture files to load into tables.

PGBOUNCER_ENABLED: bool

Enable PgBouncer connection pooling for SQLAlchemy.

get_connection_url() str[source]

Construct the full PostgreSQL connection URL.

The method prioritizes the explicit URL attribute if it is set.

Returns:

The full connection URL string.

Return type:

str

property engine: AsyncEngine

The SQLAlchemy async engine instance for database operations.

JWT Settings (JWTSettings)

class JWTSettings(ALGORITHM: str = 'Ed25519', JWT_PRIVATE_KEY: str | None = <factory>, ACCESS_TOKEN_EXPIRE_MINUTES: int = <factory>, REFRESH_TOKEN_EXPIRE_DAYS: int = <factory>)[source]

Bases: object

JWT configuration.

ALGORITHM: str = 'Ed25519'

The cryptographic algorithm used for JWS (JSON Web Signature).

JWT_PRIVATE_KEY: str | None

The Ed25519 private key in JWK (JSON Web Key) format.

This key is used for both signing and verifying tokens using the Ed25519 algorithm as specified in RFC 9864. The string must be a valid JSON containing ‘kty’, ‘crv’, ‘x’, and ‘d’ parameters.

Example

‘{“kty”:”OKP”,”crv”:”Ed25519”,”x”:”…”,”d”:”…”}’

ACCESS_TOKEN_EXPIRE_MINUTES: int

Lifetime of the access token in minutes.

REFRESH_TOKEN_EXPIRE_DAYS: int

Lifetime of the refresh token in days.

property key_object: OKPKey

The initialized Ed25519 key object for signing and verification.

Parses the JWT_PRIVATE_KEY from environment variables and returns a ready-to-use OKPKey instance.

Returns:

The cryptographic key object for Ed25519 operations.

Return type:

OKPKey

Raises:

JWTKeyConfigError – If the key is missing, not a valid JSON, or lacks required JWK parameters (kty, crv, x, d).

Redis Settings (RedisSettings)

class RedisSettings(URL: str = <factory>, SOCKET_CONNECT_TIMEOUT: int = <factory>, HEALTH_CHECK_INTERVAL: int = <factory>, SOCKET_KEEPALIVE: bool = <factory>)[source]

Bases: object

Redis configuration.

URL: str

Redis connection URL.

SOCKET_CONNECT_TIMEOUT: int

Length of time to wait (in seconds) for a connection to become active.

HEALTH_CHECK_INTERVAL: int

Length of time to wait (in seconds) before testing connection health.

SOCKET_KEEPALIVE: bool

Length of time to wait (in seconds) between keepalive commands.

property client: Redis

The configured asynchronous Redis client instance.