Multi-layer configuration management with source tracking
Actively maintained. Last release 11 days ago, commits in 6 of the last 26 weeks. A safe choice.
pip install confocalConfocal
A multi-layer configuration management library built on pydantic with source tracking and profile support.
Features
- Hierarchical config file discovery (searches parent directories)
- Profile support for different environments
- Full source tracking to explain where each config value came from
- Built on pydantic for robust validation and type safety
- Rich terminal output for config inspection
Installation
pip install confocal
Quick Start
from confocal import BaseConfig
from pydantic import Field
class MyConfig(BaseConfig):
database_url: str
name: str = Field(default="Anonymous")
debug: bool = False
# Load config from raiconfig.toml, environment variables, etc.
config = MyConfig.load()
# Show where config values came from
config.explain()
Config Sources (in order of precedence)
- Initialization arguments
- Environment variables
- Active profile from config file
- Config files (YAML or TOML)
- Default values
Using Config Files
Confocal supports both TOML and YAML config files. Specify which format to use in your config class:
Using TOML (default)
class MyConfig(BaseConfig):
model_config = SettingsConfigDict(
toml_file="config.toml",
)
Using YAML
class MyConfig(BaseConfig):
model_config = SettingsConfigDict(
yaml_file="config.yaml",
)
Using Profiles
Profile support works with both TOML and YAML files.
TOML example (raiconfig.toml):
database_url = "postgresql://prod-db:5432"
[profile.dev]
database_url = "postgresql://localhost:5432"
debug = true
[profile.test]
database_url = "postgresql://test-db:5432"
YAML example (config.yaml):
database_url: "postgresql://prod-db:5432"
profile:
dev:
database_url: "postgresql://localhost:5432"
debug: true
test:
database_url: "postgresql://test-db:5432"
Activate a profile:
export ACTIVE_PROFILE=dev
YAML Environment Variables
YAML configs support environment variable substitution: