Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

cfgx

PyPI version

Python configs with ordered composition, computed values, and CLI overrides. Loading produces an ordinary dictionary. Configuration logic stays in Python.

Documentation

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.lr reads the complete config, including later files and overrides.
  • value reads the inherited value at the current location.
  • previous.lr reads earlier definitions at another path.
  • final(1).lr reads a sibling; previous(1).lr reads its inherited definition.
  • expr.map(fn) transforms a resolved value. expr.map("x * 2") is shorthand.
  • computed(lambda get: ...) supports dynamic, conditional reads with get(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.0a3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cfgx 0.6.0a3
File Size Uploaded
cfgx-0.6.0a3.tar.gz 12.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cfgx 0.6.0a3
File Interpreter ABI Platform
cfgx-0.6.0a3-py3-none-any.whl Python 3 none any Details

Total release size: 26.9 kB

Release files / cfgx-0.6.0a3.tar.gz

Download URL cfgx-0.6.0a3.tar.gz
Size 12.3 kB
Tags Source
SHA-256 checksum
How to use checksums
39b6b92ffeeed3444c44d467d57672689dffb2697ba661109d1ab4d543d5cbe5
BLAKE2b-256 checksum
How to use checksums
a2718f039691bc92b4fabca0cc8f8f1094d66e440847aa48f436635c6c390282
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.0a3-py3-none-any.whl

Download URL cfgx-0.6.0a3-py3-none-any.whl
Size 14.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
861c476f21849b0ce10be52fa9c2f0819f2519ea806d68b506f5e2031cf823fc
BLAKE2b-256 checksum
How to use checksums
8413e01a48f0d948082cc29879aebeb95d3acc7ee53cf1c48555f5531856d697
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}
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page