Changelog¶
All notable changes to cfgcast. The format follows Keep a Changelog, and the project uses semantic versioning (before 1.0, a minor or patch release may still change the API; such changes are listed under Changed and marked breaking).
0.1.1 - 2026-11-27¶
Changed¶
- Colours are optional. clitint is no longer a dependency:
pip install "cfgcast[colour]"installs it and colours messages on a terminal, asenforced[colour]does. Without it every message is plain text, andturn_colours_off/turn_colours_onare still there and do nothing. If you want coloured messages, install thecolourextra: an upgrade from 0.1.0 without it gives plain ones.
0.1.0 - 2026-11-27¶
The first release. Requires Python 3.13 or later and enforced 0.2.0.
Added¶
- Configurations as classes. A class below
Configis a schema: each annotated attribute is a key, its type says what the value must be, a default makes it optional. Every value is checked and converted by enforced (coerceanddeepalways on). Instances are frozen, keyword-only dataclasses. - Options as class keywords:
strict(unknown keys refused, the default;Falseignores them with a warning),frozen,env_prefix, andkeys = "kebab-case". - Inheritance: a class below a configuration is one too, with the fields above it and its own.
strict,env_prefixandkeysare inherited;frozenis set by each class. - Sections: a field whose type is another configuration (or a plain dataclass) is a nested table. Lists,
tuples and dictionaries of sections (
list[Server],dict[str, Server]) are built item by item. - Formats: JSON, TOML, ini (
.ini,.cfg) and YAML (withcfgcast[yaml]), read and written. YAML is read with YAML 1.2 booleans (nostays"no"). ini gets nesting ([db.pool]) and lists (a, b, c). - Loading with
App.load(file)orApp.from_dict(data), both typed for checkers (App.loadgives anApp): - several files in layers, a later file winning;
optional("local.toml")for one that may be absent; - environment variables with a prefix (
APP_DB__PORTisdb.port), a.envfile, and secrets from files (APP_DB__PASSWORD_FILE); section = "tool.myapp"for one table of a bigger file such aspyproject.toml;overridesfor one run, andparse_overrides(sys.argv[1:], App)to make them fromdb.port=9090texts.- Every problem at once: one
ConfigErrorwith each problem's source, line and key path (app.toml:12: db.port: ...), anderrors()/json()in pydantic's shape. An exception raised by a__post_init__is a problem like the others. - Secrets are never shown: a
SecretStrvalue is masked in every message,errors(), warning andrepr; an unknown key's value is never shown at all. sources_of(app): where each value came from, by key path (file:line, a variable,overrides, or(default)).- Writing:
write(app, file)in any format, every key written, the file replaced whole or not at all.to_text(app)gives the same text with secrets masked;to_dict(app, plain = True)only what JSON holds. - Templates:
write_template(App, "app.toml")writes every key with its default, type and doc, required keys and secrets commented out (TOML, YAML, ini).field(doc = ...)adds a line above a key. field(key = ...)for keys that aren't Python names (max-size,class).- Dates and durations: dates and times in every format; a
timedeltais text with a unit (1h30m,PT30S), written in the short form. Adatefield takes a day, not a moment. FrozenConfigErrorfor an assignment to a frozen configuration: adataclasses.FrozenInstanceErrorthat names the key path, never the value.ConfigWarningnames the keysstrict = Falseignored, and where the class is written.- Coloured messages on a terminal (clitint), switched off with
CLITINT_COLOURS_OFF=1,NO_COLORorturn_colours_off().