Skip to main content

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

AttributeTypeDescription
model_configSettingsConfigDict = 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_STRstr = "/api/v1"The URL prefix for version 1 of the API endpoints.
SECRET_KEYstrA cryptographically secure string used for signing session cookies and tokens.
ACCESS_TOKEN_EXPIRE_MINUTESint = 11520The duration in minutes before an issued access token becomes invalid.
FRONTEND_HOSTstr = "http://localhost:5173"The base URL of the frontend application used for CORS and email links.
ENVIRONMENTLiteral["local", "staging", "production"] = "local"The current deployment stage which dictates security enforcement and logging levels.
BACKEND_CORS_ORIGINS`list[AnyUrl]str` = []
PROJECT_NAMEstrThe display name of the project used in emails and documentation.
SENTRY_DSN`HttpUrlNone` = null
POSTGRES_SERVERstrThe hostname or IP address of the PostgreSQL database server.
POSTGRES_PORTint = 5432The port number on which the PostgreSQL server is listening.
POSTGRES_USERstrThe username used to authenticate with the PostgreSQL database.
POSTGRES_PASSWORDstr = ""The password used to authenticate with the PostgreSQL database.
POSTGRES_DBstr = ""The name of the specific database to connect to on the PostgreSQL server.
SMTP_TLSbool = trueWhether to use Transport Layer Security (TLS) when connecting to the SMTP server.
SMTP_SSLbool = falseWhether to use Secure Sockets Layer (SSL) when connecting to the SMTP server.
SMTP_PORTint = 587The port number used for outgoing SMTP mail server connections.
SMTP_HOST`strNone` = null
SMTP_USER`strNone` = null
SMTP_PASSWORD`strNone` = null
EMAILS_FROM_EMAIL`EmailStrNone` = null
EMAILS_FROM_NAME`strNone` = null
EMAIL_RESET_TOKEN_EXPIRE_HOURSint = 48The duration in hours before a password reset token expires.
EMAIL_TEST_USEREmailStr = "test@example.com"The email address used for sending test emails during development.
FIRST_SUPERUSEREmailStrThe email address for the initial administrative user created on startup.
FIRST_SUPERUSER_PASSWORDstrThe 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

TypeDescription
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

TypeDescription
PostgresDsnA 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

TypeDescription
boolTrue if both the SMTP host and the sender email address are configured; otherwise False.