cfgx
Python configs with ordered composition, computed values, and CLI overrides. Loading produces an ordinary dictionary. Configuration logic stays in Python.
pip install cfgx
Define a base:
# base.py
from cfgx import final
config = {
"steps": 96_000,
"lr": 3e-4,
"backbone_lr": final.lr * 0.1,
"cooldown_steps": final.steps // 10,
}
Compose a variant with a tuple of sources:
# finetune.py
from cfgx import value
config = "base.py", {"steps": 48_000, "lr": value * 0.5}
Load it with optional overrides:
from cfgx import load
cfg = load("finetune.py", overrides=["lr=expr:value * 0.1"])
assert cfg["steps"] == 48_000
assert cfg["backbone_lr"] == cfg["lr"] * 0.1
Overrides contribute ordinary layers: optimizer.lr=1e-4 adds
{"optimizer": {"lr": replace(1e-4)}}, and optimizer.decay!= adds
{"optimizer": {"decay": delete}}. Use expr:{...} for a complete layer.
Dictionaries merge recursively, including computed dictionaries. Lists and tuples
replace earlier sequences. Use replace(x) to replace a dictionary and delete
to remove a dictionary entry.
Use include("model.py") to contribute a file at a nested location, and
compose("defaults.py", {...}) for ordered contributions there. Root source
strings and tuples are shorthand for these operations; strings and tuples in
config values remain data. The mental model explains these
contexts and how nested layers read inherited values.
final.lrreads the complete config, including later files and overrides.valuereads the inherited value at the current location.previous.lrreads earlier definitions at another path.final(1).lrreads a sibling;previous(1).lrreads its inherited definition.expr.map(fn)transforms a resolved value.expr.map("x * 2")is shorthand.computed(lambda get: ...)supports dynamic, conditional reads withget(expr)..default(...),.keys(),.len(), and.exists()compose with other expressions.
from cfgx import computed, delete, final
config = {
"resume": False,
"checkpoint": computed(
lambda get: get(final.checkpoint_path) if get(final.resume) else delete
),
}
Exact built-in dictionaries, lists, and tuples are rebuilt independently for each output location. Other objects are opaque and retain identity. Avoid side effects when working with opaque values or unknown types.
See composition, expressions, overrides, and the resolution contract. Training example demonstrates a compact setup with model and dataset composition, learning-rate scaling, computed checkpoints, and dataset transformations.
Snapshots and formatting remain available through dump, dumps, and format.
A snapshot preserves resolved values, not their formulas.
Metadata
Release files for cfgx 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cfgx-0.6.0.tar.gz | 12.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cfgx-0.6.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.9 kB
Release files / cfgx-0.6.0.tar.gz
| Download URL | cfgx-0.6.0.tar.gz |
|---|---|
| Size | 12.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
13c848471b80b48df8b00e809c3fd432bd86d2c931882440ebb30ae1772cbf32
|
|
BLAKE2b-256 checksum How to use checksums |
efc60f75d426f77f07eca98523e511e84059ac17defb3b9c2e678e2d9be7df90
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / cfgx-0.6.0-py3-none-any.whl
| Download URL | cfgx-0.6.0-py3-none-any.whl |
|---|---|
| Size | 14.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b0cb29a05d5fdbfb6886e4aae3f5b617245215204851204457bb9593339c3b49
|
|
BLAKE2b-256 checksum How to use checksums |
dcf126a9f8bb3c2a7522a710b5f0c54a155139e7bab127c92c41c5a3eb696269
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|