Settings¶
commons.settings
¶
Classes:
| Name | Description |
|---|---|
AppSettings |
Common app settings. |
OpenAISettings |
Common settings class for OpenAI settings. |
AzureOpenAISettings |
Common settings class for native Azure OpenAI settings. |
AzureOpenAIEmbeddingSettings |
Settings class for Azure OpenAI embedding models. |
MSSQLSettings |
MSSQL database connection settings. |
LocalDatabaseSettings |
Local SQLite database settings. |
DatabaseSettings |
Database configuration settings. |
LocalStorageSettings |
Local filesystem storage settings. |
AzureStorageSettings |
Azure Blob Storage settings. |
StorageSettings |
Storage configuration settings. |
RoleAssignmentConfig |
Configuration for a role assignment. |
StandardUser |
A user defined in settings configuration. |
StandardUserSettings |
Settings container for user definitions. |
SMTPSettings |
Connection to an SMTP server for sending mails. |
Functions:
| Name | Description |
|---|---|
read_settings |
|
read_settings_object |
Read a nested settings dict and transform it into an object. |
Attributes:
| Name | Type | Description |
|---|---|---|
T |
|
|
LOG |
|
AppSettings
dataclass
¶
AppSettings(
version: str = "",
environment: str = "",
data_dir: str = "",
public_url: str = "",
**_kwargs
)
Common app settings.
Methods:
| Name | Description |
|---|---|
read |
|
Attributes:
| Name | Type | Description |
|---|---|---|
data_dir |
Path
|
|
version |
str
|
|
environment |
str
|
|
public_url |
str
|
Public URL of the app, e.g. |
Source code in src/commons/settings.py
public_url
instance-attribute
¶
Public URL of the app, e.g. https://app.example.com, without a trailing slash; empty when unknown (locally).
read
staticmethod
¶
read() -> AppSettings
OpenAISettings
dataclass
¶
OpenAISettings(
api_key: str = "",
model: str = "gpt-5-mini",
embedding_model: str = "text-embedding-3-small",
**_kwargs
)
Common settings class for OpenAI settings.
Methods:
| Name | Description |
|---|---|
read |
|
Attributes:
| Name | Type | Description |
|---|---|---|
model |
str
|
|
embedding_model |
str
|
|
api_key |
str
|
|
Source code in src/commons/settings.py
read
staticmethod
¶
read() -> OpenAISettings
AzureOpenAISettings
dataclass
¶
AzureOpenAISettings(
api_key: str = "",
azure_deployment: str = "gpt-4o-mini",
azure_endpoint: str = "",
api_version: str = "2025-01-01-preview",
embedding_model: str = "text-embedding-3-small",
**_kwargs
)
Common settings class for native Azure OpenAI settings.
Methods:
| Name | Description |
|---|---|
read |
|
Attributes:
| Name | Type | Description |
|---|---|---|
azure_deployment |
str
|
|
azure_endpoint |
str
|
|
api_version |
str
|
|
embedding_model |
str
|
|
api_key |
str
|
|
Source code in src/commons/settings.py
read
staticmethod
¶
read() -> AzureOpenAISettings
AzureOpenAIEmbeddingSettings
dataclass
¶
AzureOpenAIEmbeddingSettings(
api_key: str = "",
azure_deployment: str = "text-embedding-3-small",
azure_endpoint: str = "",
api_version: str = "2023-05-15",
**_kwargs
)
Settings class for Azure OpenAI embedding models.
Methods:
| Name | Description |
|---|---|
read |
|
Attributes:
| Name | Type | Description |
|---|---|---|
azure_deployment |
str
|
|
azure_endpoint |
str
|
|
api_version |
str
|
|
api_key |
str
|
|
Source code in src/commons/settings.py
read
staticmethod
¶
read() -> AzureOpenAIEmbeddingSettings
MSSQLSettings
dataclass
¶
MSSQLSettings(
server: str = "",
database: str = "",
username: str = "",
password: str = "",
port: int = 1433,
query: dict[str, str] | None = None,
)
MSSQL database connection settings.
Attributes:
| Name | Type | Description |
|---|---|---|
server |
str
|
The FQN of the database server. |
database |
str
|
The name of the database to access. |
username |
str
|
The username used to access the database. |
password |
str
|
The password to access the database. |
port |
int
|
TCP port of the database server. Defaults to 1433. |
query |
dict[str, str] | None
|
Optional overrides for the ODBC connection-string query parameters (driver, Encrypt, TrustServerCertificate, Connection Timeout, ...). Values provided here are merged on top of the built-in defaults, so only keys that need to change must be listed. |
LocalDatabaseSettings
dataclass
¶
DatabaseSettings
dataclass
¶
DatabaseSettings(
mode: Literal["local", "mssql"] = "local",
local: dict[str, Any] | None = None,
mssql: dict[str, Any] | None = None,
)
Database configuration settings.
Attributes:
| Name | Type | Description |
|---|---|---|
mode |
Literal['local', 'mssql']
|
The database mode for the application.
- |
local |
LocalDatabaseSettings | None
|
Local SQLite database settings (optional, used when mode is |
mssql |
MSSQLSettings | None
|
MSSQL connection settings (required when mode is |
Methods:
| Name | Description |
|---|---|
read |
Read database settings from configuration. |
Source code in src/commons/settings.py
local
class-attribute
instance-attribute
¶
local: LocalDatabaseSettings | None = (
LocalDatabaseSettings(**local) if local else None
)
mssql
class-attribute
instance-attribute
¶
mssql: MSSQLSettings | None = (
MSSQLSettings(**mssql) if mssql else None
)
LocalStorageSettings
dataclass
¶
Local filesystem storage settings.
Attributes:
| Name | Type | Description |
|---|---|---|
root |
str | None
|
The root directory for the local file store. If None, falls back to
|
Source code in src/commons/settings.py
AzureStorageSettings
dataclass
¶
AzureStorageSettings(
auth_mode: Literal[
"default_credential",
"connection_string",
"account_key",
] = "default_credential",
account_url: str = "",
container: str = "",
connection_string: str = "",
account_name: str = "",
account_key: str = "",
**_kwargs
)
Azure Blob Storage settings.
Attributes:
| Name | Type | Description |
|---|---|---|
auth_mode |
Literal['default_credential', 'connection_string', 'account_key']
|
Authentication mode for connecting to Azure Storage.
- |
account_url |
str
|
Blob service endpoint, e.g.
|
container |
str
|
Name of the blob container that backs this Files instance. |
account_name |
str
|
Storage account name (used with |
Methods:
| Name | Description |
|---|---|
read |
|
Source code in src/commons/settings.py
auth_mode
class-attribute
instance-attribute
¶
read
staticmethod
¶
read() -> AzureStorageSettings
StorageSettings
dataclass
¶
StorageSettings(
mode: Literal["local", "sql", "azure"] = "local",
local: (
dict[str, Any] | LocalStorageSettings | None
) = None,
azure: (
dict[str, Any] | AzureStorageSettings | None
) = None,
**_kwargs: Any
)
Storage configuration settings. Unknown configuration keys are ignored for forward compatibility.
Attributes:
| Name | Type | Description |
|---|---|---|
mode |
Literal['local', 'sql', 'azure']
|
The storage backend for the application.
- |
local |
LocalStorageSettings | None
|
Local filesystem settings (optional, used when mode is |
azure |
AzureStorageSettings | None
|
Azure Blob Storage settings (required when mode is |
Methods:
| Name | Description |
|---|---|
read |
|
Source code in src/commons/settings.py
read
staticmethod
¶
read() -> StorageSettings
RoleAssignmentConfig
¶
StandardUser
¶
Bases: BaseModel
A user defined in settings configuration.
Used for bootstrapping users from configuration files (e.g., settings.toml).
At most one of password or password_hash may be set. Prefer
password_hash so no plain-text password is kept in the settings. A user
with neither has no password: they can't sign in with a password, only by
other means such as an email link or code (commons.users.login_tokens).
Generate a hash with the command line helper (prompts for the password)::
python -m commons.users hash-password
# or non-interactively
echo -n "secret" | python -m commons.users hash-password --stdin
and put the printed value into the settings::
[[users]]
username = "john.doe"
firstname = "John"
lastname = "Doe"
email = "john@example.com"
password_hash = "$2b$12$..."
The hash must match the repository's password verifier (bcrypt by default).
Attributes:
| Name | Type | Description |
|---|---|---|
username |
str
|
|
firstname |
str
|
|
lastname |
str
|
|
email |
str
|
|
password |
str | None
|
|
password_hash |
str | None
|
|
roles |
list[RoleAssignmentConfig]
|
|
username
class-attribute
instance-attribute
¶
firstname
class-attribute
instance-attribute
¶
lastname
class-attribute
instance-attribute
¶
password
class-attribute
instance-attribute
¶
password: str | None = Field(
default=None,
description="Plain-text password (will be hashed when creating the user).",
)
password_hash
class-attribute
instance-attribute
¶
password_hash: str | None = Field(
default=None,
description="Pre-computed password hash (stored as-is when creating the user).",
)
roles
class-attribute
instance-attribute
¶
roles: list[RoleAssignmentConfig] = Field(
default_factory=list,
description="List of role names to assign to the user.",
)
StandardUserSettings
¶
Bases: BaseModel
Settings container for user definitions.
Reads user configuration from settings files and provides a list of users
to be created or synchronized with the user repository (see
UsersRepository.init_from_settings()).
Passwords should be configured as password_hash per user; create the hash
with python -m commons.users hash-password (see StandardUser).
Methods:
| Name | Description |
|---|---|
read |
Read users settings from configuration. |
Attributes:
| Name | Type | Description |
|---|---|---|
model_config |
|
|
users |
list[StandardUser]
|
|
users
class-attribute
instance-attribute
¶
users: list[StandardUser] = Field(
default_factory=list,
description="List of users defined in configuration.",
)
SMTPSettings
¶
Bases: BaseModel
Connection to an SMTP server for sending mails.
Read from app.smtp.*; host and from_address are required. Not
specific to login mails: every mail sender of an app can use it (first
commons.users.login_tokens.SMTPLoginTokenSender). The connection is
always encrypted: ssl uses TLS from the start (port 465),
starttls upgrades the connection (port 587).
TOML (e.g. a Strato mailbox)::
[app.smtp] # settings.toml
host = "smtp.strato.de"
security = "ssl" # port 465; default "starttls" (587)
username = "login@example.com"
from_address = "CaseSight <login@example.com>" # must belong to the mailbox
[app.smtp] # settings.secrets.toml
password = "..."
Env var overrides follow the standard pattern, e.g. APP__SMTP__PASSWORD.
Env var values are evaluated as Python literals, so a password that looks
like a number must be quoted: APP__SMTP__PASSWORD='"123456"'.
The password is a SecretStr: it doesn't show in repr() or str();
read it with settings.password.get_secret_value().
Methods:
| Name | Description |
|---|---|
read |
Read the SMTP settings from |
Attributes:
| Name | Type | Description |
|---|---|---|
model_config |
|
|
host |
str
|
|
port |
int | None
|
|
security |
Literal['ssl', 'starttls']
|
|
username |
str
|
|
password |
SecretStr
|
|
from_address |
str
|
|
timeout |
float
|
|
host
class-attribute
instance-attribute
¶
port
class-attribute
instance-attribute
¶
port: int | None = Field(
default=None,
description="Port; defaults to 465 for `ssl` and 587 for `starttls`.",
)
security
class-attribute
instance-attribute
¶
security: Literal["ssl", "starttls"] = Field(
default="starttls",
description="How the connection is encrypted.",
)
username
class-attribute
instance-attribute
¶
password
class-attribute
instance-attribute
¶
from_address
class-attribute
instance-attribute
¶
from_address: str = Field(
min_length=1,
description="Sender address, e.g. `App <login@example.com>`.",
)
timeout
class-attribute
instance-attribute
¶
timeout: float = Field(
default=30,
gt=0,
description="Seconds to wait for the server before failing.",
)
read
staticmethod
¶
read() -> SMTPSettings
Read the SMTP settings from app.smtp.
Raises:
| Type | Description |
|---|---|
ValidationError
|
If |
Source code in src/commons/settings.py
read_settings
cached
¶
read_settings(
user_home_settings_dir: str = ".wellner",
user_home_settings_file: str = "settings.toml",
) -> dict
Source code in src/commons/settings.py
read_settings_object
¶
read_settings_object(
key: str,
model_cls: Type[T],
user_home_settings_dir: str = ".wellner",
user_home_settings_file: str = "settings.toml",
) -> T
Read a nested settings dict and transform it into an object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Dot-separated path to the config section (e.g., "vectorstore.chroma") |
required |
model_cls
|
Type[T]
|
Class to instantiate. If it has a |
required |
user_home_settings_dir
|
str
|
Directory name in user home for settings |
'.wellner'
|
user_home_settings_file
|
str
|
Settings filename in user home directory |
'settings.toml'
|
Returns:
| Type | Description |
|---|---|
T
|
Instance of model_cls populated with the config values |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the key path doesn't exist in settings |