Settings
This class manages application configuration by loading environment variables from a file and validating them against a defined schema. It handles critical settings for database connections, security keys, CORS origins, and SMTP email services while providing computed properties for derived configuration values. Additionally, it includes validation logic to ensure sensitive credentials are not left as default values in non-local environments.
Attributes
| Attribute | Type | Description |
|---|---|---|
| model_config | SettingsConfigDict = SettingsConfigDict(env_file="../.env", env_ignore_empty=True, extra="ignore") | Configuration dictionary for the Pydantic model that defines environment file loading and validation behavior. |
| API_V1_STR | str = "/api/v1" | The URL prefix for version 1 of the API endpoints. |
| SECRET_KEY | str | A cryptographically secure string used for signing session cookies and tokens. |
| ACCESS_TOKEN_EXPIRE_MINUTES | int = 11520 | The duration in minutes before an issued access token becomes invalid. |
| FRONTEND_HOST | str = "http://localhost:5173" | The base URL of the frontend application used for CORS and email links. |
| ENVIRONMENT | Literal["local", "staging", "production"] = "local" | The current deployment stage which dictates security enforcement and logging levels. |
| BACKEND_CORS_ORIGINS | `list[AnyUrl] | str` = [] |
| PROJECT_NAME | str | The display name of the project used in emails and documentation. |
| SENTRY_DSN | `HttpUrl | None` = null |
| POSTGRES_SERVER | str | The hostname or IP address of the PostgreSQL database server. |
| POSTGRES_PORT | int = 5432 | The port number on which the PostgreSQL server is listening. |
| POSTGRES_USER | str | The username used to authenticate with the PostgreSQL database. |
| POSTGRES_PASSWORD | str = "" | The password used to authenticate with the PostgreSQL database. |
| POSTGRES_DB | str = "" | The name of the specific database to connect to on the PostgreSQL server. |
| SMTP_TLS | bool = true | Whether to use Transport Layer Security (TLS) when connecting to the SMTP server. |
| SMTP_SSL | bool = false | Whether to use Secure Sockets Layer (SSL) when connecting to the SMTP server. |
| SMTP_PORT | int = 587 | The port number used for outgoing SMTP mail server connections. |
| SMTP_HOST | `str | None` = null |
| SMTP_USER | `str | None` = null |
| SMTP_PASSWORD | `str | None` = null |
| EMAILS_FROM_EMAIL | `EmailStr | None` = null |
| EMAILS_FROM_NAME | `str | None` = null |
| EMAIL_RESET_TOKEN_EXPIRE_HOURS | int = 48 | The duration in hours before a password reset token expires. |
| EMAIL_TEST_USER | EmailStr = "test@example.com" | The email address used for sending test emails during development. |
| FIRST_SUPERUSER | EmailStr | The email address for the initial administrative user created on startup. |
| FIRST_SUPERUSER_PASSWORD | str | The password for the initial administrative user created on startup. |
Methods
all_cors_origins()
@classmethod
def all_cors_origins() - > list[str]
Aggregates and cleanses all allowed CORS origins by combining configured backend origins with the frontend host. This ensures all relevant client domains are authorized to interact with the API.
Returns
| Type | Description |
|---|---|
list[str] | A list of normalized URL strings representing authorized origins, with trailing slashes removed. |
SQLALCHEMY_DATABASE_URI()
@classmethod
def SQLALCHEMY_DATABASE_URI() - > PostgresDsn
Constructs the full PostgreSQL connection URI using the individual database configuration components. This URI is used by SQLAlchemy to establish the database connection pool.
Returns
| Type | Description |
|---|---|
PostgresDsn | A validated PostgreSQL DSN object containing the protocol, credentials, host, and database name. |
emails_enabled()
@classmethod
def emails_enabled() - > bool
Determines if the application is configured to send emails based on the presence of required SMTP settings. This is used to conditionally enable or disable email-related features.
Returns
| Type | Description |
|---|---|
bool | True if both the SMTP host and the sender email address are configured; otherwise False. |