Skip to content

Configuration reference

All settings are managed by AppSettings (Pydantic Settings) and can be provided via environment variables or a .env file.

Core

VariableDefaultDescription
APP_ENVlocalRuntime environment: local / test / production
APP_DEBUGfalseInclude exception messages in 500 responses when true
APP_NAMEnene2-pythonApplication name

Security

VariableDefaultDescription
SECURITY_HEADERS_ENABLEDtrueAdd security headers to every response
MAX_BODY_SIZE1048576Maximum request body size in bytes (default 1 MiB)

Security headers added when enabled:

HeaderValue
X-Content-Type-Optionsnosniff
X-Frame-OptionsDENY
Referrer-Policystrict-origin-when-cross-origin
Content-Security-Policydefault-src 'self'
Permissions-Policygeolocation=(), microphone=()

Rate limiting

VariableDefaultDescription
THROTTLE_ENABLEDtrueEnable rate limiting
THROTTLE_LIMIT60Maximum requests per window
THROTTLE_WINDOW60Window size in seconds

Uses a fixed-window algorithm keyed on client IP. Exceeding the limit returns 429 Too Many Requests with a Retry-After header.

CORS

VariableDefaultDescription
CORS_ENABLEDfalseEnable CORS middleware
CORS_ORIGINS[]Allowed origins (comma-separated)
CORS_ALLOW_CREDENTIALSfalseAllow credentials
CORS_ALLOW_METHODSGET,POST,PUT,DELETE,OPTIONSAllowed methods
CORS_ALLOW_HEADERS*Allowed headers

CORS_ORIGINS=* is prohibited. Always specify explicit origins.

Authentication

VariableDefaultDescription
BEARER_TOKEN_ENABLEDfalseEnable Bearer Token auth
BEARER_TOKENS[]Valid tokens — JSON array format: ["tok-1","tok-2"]
API_KEY_ENABLEDfalseEnable API Key auth
API_KEYS[]Valid API keys — JSON array format: ["key-1","key-2"]

List fields require JSON array syntax in .env. Writing BEARER_TOKENS=token-1 (plain string) causes a JSONDecodeError at startup. Always use BEARER_TOKENS=["token-1","token-2"]. The same applies to API_KEYS and CORS_ORIGINS.

Database

VariableDefaultDescription
DB_ADAPTERsqlitesqlite / mysql / pgsql
DB_NAME:memory:SQLite file path or DB name
DB_HOSTlocalhostDatabase host (ignored for SQLite)
DB_PORT3306Database port (ignored for SQLite)
DB_USER""Database user (ignored for SQLite)
DB_PASSWORD""Database password — stored as SecretStr, never logged

Generated db_url

AppSettings.db_url is a computed property built from the variables above. The table below shows what URL is generated for each adapter + common DB_NAME values:

DB_ADAPTERDB_NAMEGenerated db_url
sqlite:memory:sqlite:///:memory:
sqlite./data/app.dbsqlite:///./data/app.db
sqlite/var/lib/app.dbsqlite:////var/lib/app.db
mysqlmydbmysql+pymysql://user:pass@localhost:3306/mydb
pgsqlmydbpostgresql+psycopg2://user:pass@localhost:5432/mydb

For SQLite in-memory databases (DB_NAME=:memory:), pass poolclass=StaticPool to create_engine() so all connections share the same in-process database. See the SQLAlchemy repository how-to for details.

Example .env

dotenv
APP_ENV=production
APP_DEBUG=false

THROTTLE_ENABLED=true
THROTTLE_LIMIT=100
THROTTLE_WINDOW=60

CORS_ENABLED=true
CORS_ORIGINS=["https://example.com","https://app.example.com"]

BEARER_TOKEN_ENABLED=true
BEARER_TOKENS=["secret-token-1","secret-token-2"]

DB_ADAPTER=mysql
DB_HOST=db.example.com
DB_PORT=3306
DB_NAME=myapp
DB_USER=myuser
DB_PASSWORD=supersecret

Commit .env.example with empty values. Keep the real .env in .gitignore.

Released under the MIT License.