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
neo4j_config = settings.Neo4j()
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 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 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: [server] environment = "production" host = "0.0.0.0" port = 8080
[neo4j]
url = "neo4j://neo4j-prod:7687"
user = "admin"
[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 src/imbi_common/settings.py
Neo4j ¶
Bases: BaseSettings
extract_credentials_from_url ¶
Extract username/password from URL and strip them from the URL.
If the URL contains embedded credentials (e.g., neo4j://username:password@localhost:7687), extract them and set the user and password fields, then clean the URL.
Source code in src/imbi_common/settings.py
Clickhouse ¶
Bases: BaseSettings
ServerConfig ¶
Bases: BaseSettings
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.
generate_encryption_key_if_missing ¶
Generate encryption key if not provided (Phase 5).
Auto-generates a Fernet encryption key if IMBI_AUTH_ENCRYPTION_KEY is not set in the environment. Logs a warning since this key should be stable across restarts in production.