Settings¶
The settings module provides type-safe configuration management using Pydantic Settings.
Overview¶
Configuration is loaded from multiple sources in priority order:
1. Environment variables (highest priority)
2. ./config.toml (project directory)
3. ~/.config/imbi/config.toml (user directory)
4. /etc/imbi/config.toml (system directory)
5. Built-in defaults (lowest priority)
Loading Configuration¶
from imbi.common import settings
# Load full configuration
config = settings.load_config()
# Access individual settings sections
postgres_config = settings.Postgres()
clickhouse_config = settings.Clickhouse()
auth_config = settings.Auth()
API Reference¶
load_config ¶
Load configuration from config.toml files with environment overrides.
Checks for config files in priority order: 1. ./config.toml (project root) 2. ~/.config/imbi/config.toml (user config) 3. /etc/imbi/config.toml (system config)
Environment variables always override config file values.
Returns:
| Type | Description |
|---|---|
Configuration
|
Configuration object with merged settings |
Source code in libraries/common/src/imbi/common/settings.py
get_auth_settings ¶
Get the singleton Auth settings instance.
This ensures the JWT secret remains stable across requests when auto-generated (i.e., when IMBI_AUTH_JWT_SECRET is not set in env).
Returns:
| Type | Description |
|---|---|
Auth
|
The singleton Auth settings instance. |
Source code in libraries/common/src/imbi/common/settings.py
get_config_settings ¶
Get the singleton ConfigSecrets settings instance.
This ensures the config encryption key remains stable across requests when auto-generated (i.e., when IMBI_CONFIG_ENCRYPTION_KEY is not set in env).
Returns:
| Type | Description |
|---|---|
ConfigSecrets
|
The singleton ConfigSecrets settings instance. |
Source code in libraries/common/src/imbi/common/settings.py
Configuration ¶
Bases: BaseModel
Root configuration combining all shared settings sections.
Supports loading from config.toml files with environment variable overrides. Config files are checked in this priority order: 1. ./config.toml (project root) 2. ~/.config/imbi/config.toml (user config) 3. /etc/imbi/config.toml (system config)
Environment variables always take precedence over config file values.
Example config.toml: [postgres] url = "postgresql://postgres:secret@db-prod:5432/imbi"
[auth]
jwt_secret = "your-secret-here"
access_token_expire_seconds = 7200
merge_env_with_config
classmethod
¶
Merge environment variables with config file data.
For each BaseSettings submodel, instantiate it with the config file data as kwargs. This allows BaseSettings to use environment variables as defaults for any fields not provided in the config file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any]
|
Raw config data from TOML file |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Config data with BaseSettings instances properly constructed |
Source code in libraries/common/src/imbi/common/settings.py
Postgres ¶
Bases: BaseSettings
PostgreSQL connection settings.
Clickhouse ¶
Bases: BaseSettings
cluster_name
class-attribute
instance-attribute
¶
Name of the ClickHouse cluster (CLICKHOUSE_CLUSTER_NAME).
When set, setup_schema() injects ON CLUSTER <cluster_name> into
the CREATE DDL statements loaded from schemata.toml so the schema
is created across every node of the cluster. Leave unset for a
single-node deployment.
Auth ¶
Bases: BaseSettings
Authentication settings shared across Imbi services.
Contains only JWT and encryption configuration needed by any service that verifies tokens or handles encrypted data.
validate_secrets ¶
Enforce explicit secrets outside development; auto-generate in dev.
When ENVIRONMENT is anything other than development (the
default), both IMBI_AUTH_JWT_SECRET and
IMBI_AUTH_ENCRYPTION_KEY must be configured explicitly: booting
with auto-generated per-process values would silently invalidate
every issued token (and make every encrypted value undecryptable)
on the next restart, so it is refused. In development the historical
auto-generation behavior is preserved.
model_fields_set distinguishes an explicitly-supplied value
(env var, config file, or kwarg) from a default, and is inspected
before the dev-mode auto-generation below mutates it.
Source code in libraries/common/src/imbi/common/settings.py
ConfigSecrets ¶
Bases: BaseSettings
Encryption settings for persisted configuration secrets.
Provides a dedicated Fernet key, separate from :class:Auth, used to
encrypt sensitive configuration values (e.g. external MCP server
credentials) at rest. Keeping it distinct from the JWT/token encryption
key lets the two be rotated independently.
validate_secrets ¶
Enforce an explicit key outside development; auto-generate in dev.
When ENVIRONMENT is anything other than development (the
default), IMBI_CONFIG_ENCRYPTION_KEY must be configured
explicitly: booting with an auto-generated per-process value would
silently make every encrypted configuration value undecryptable on
the next restart, so it is refused. In development the historical
auto-generation behavior is preserved.
model_fields_set distinguishes an explicitly-supplied value
(env var, config file, or kwarg) from a default, and is inspected
before the dev-mode auto-generation below mutates it.
Source code in libraries/common/src/imbi/common/settings.py
SSL ¶
Bases: BaseSettings
SSL configuration settings.
configure ¶
Configure the default SSL context if cert_dir is set.
Patches ssl.create_default_context and ssl._create_default_https_context to load CA certificates from cert_dir on every call.