Confit

raw JSON →
0.10.2 verified Fri May 01 auth: no python

Confit is a smart configuration framework for Python that supports hierarchical configs, CLI overrides, and validation via pydantic. It merges YAML/TOML/JSON config files with command-line arguments and environment variables. Current version is 0.10.2, with frequent minor releases.

pip install confit
error AttributeError: module 'confit' has no attribute 'ConfitConfig'
cause The class was renamed to `Config` in v0.10.0.
fix
Use from confit import Config.
error confit.errors.ConfigError: Cannot merge configs: expected list, got str
cause `Config()` expects a list of file paths for merging, not a single string.
fix
Wrap the path in a list: Config(['config.yaml']) or Config(['base.yaml', 'override.yaml']).
breaking In version 0.10.0, the `Config` class was renamed from `ConfitConfig` to `Config`. Old code using `ConfitConfig` will break.
fix Use `from confit import Config` instead.
deprecated The `--config` CLI flag is deprecated in favor of position-based config file loading.
fix Specify config file path as a positional argument: `python script.py path/to/config.yaml`.
gotcha Merging multiple config files only works if they are specified as a list. Single string paths won't merge.
fix Use `Config(['base.yaml', 'override.yaml'])` instead of `Config('base.yaml')`.

Load a YAML config file and override keys via CLI-style strings.

import os
from confit import Config

# Load config from YAML with CLI overrides
cfg = Config('config.yaml', overrides=['key=value'])
print(cfg.to_dict())