Skip to main content

onefig

PyPI Downloads Python versions CI License: MIT Docs Ruff Checked with mypy

pip install onefig

onefig

A simple, typed YAML config system for Python that tries to unite the best aspects of various config libraries into one API.

One config to rule them all!

Why?

Configuration management is at the heart of most ML workflows, but can be wildly annoying to deal with. This repo is a simple pythonic config management system that tries to tie in the best aspects of OmegaConf (flexible YAML loading and interpolation) and Pydantic v2 (strict typing and validation), in a simple API. onefig takes heavy inspiration from Hydra, Pydra, and tyro.

onefig was built for my own projects, but figured others might find it useful too. Contributions and suggestions are welcome!

Integrations

Weights & Biases

WandbSweepConfig validates a wandb sweep config as soon as you load it, catching bad distributions or out-of-bounds values before the sweep launches, and lists a grid or random sweep's trials without wandb's sweep server. See the integrations docs.

Quickstart

"Speak, friend, and enter."

Define a ConfigModel which contains fields and their defaults. Using our built in parser, you can then directly override these from commandline as shown below:

# script.py
from onefig import ConfigModel

class ModelCfg(ConfigModel):
    name: str = "tiny-bert"
    lr: float = 1e-4

class TrainCfg(ConfigModel):
    epochs: int = 10
    model: ModelCfg = ModelCfg()

def main():
    cfg = TrainCfg()
    cfg.update_from_cli()                  # picks up sys.argv[1:], supports --help / --show

if __name__ == "__main__":
    main()

Run it:

python script.py                          # uses schema defaults
python script.py lr=0.001 epochs=20       # CLI overrides
python script.py model.name=bert-base     # dotted-path override
python script.py lr=0.001 --show          # print resolved config and exit
python script.py --help                   # list every overridable field

Runnable demo: examples/01_cli_overrides.py.

Loading from YAML

When you want defaults to live alongside the code in a config file, swap the direct constructor for load:

# train.yaml
epochs: 5
model:
  name: tiny-bert
  lr: 0.001
cfg = TrainCfg.load("train")              # name lookup, or pass a path
cfg.update_from_cli()                      # CLI still overrides
cfg.freeze()

YAML files support ${...} interpolation and extends: composition; see YAML composition.

Runnable demo: examples/02_basic.py.

Features

  • YAML + interpolation — ${other.key}, ${oc.env:VAR} resolved via OmegaConf.
  • YAML composition — top-level extends: base.yaml (or a list) deep-merges parent files into the current one before validation, with cycle detection and cross-file interpolation.
  • Typed configs — Pydantic validates on load and on every assignment; unknown fields rejected (extra="forbid").
  • Two CLI override paths — argparse-free update_from_cli for quick scripts, or update_from_args for custom argparse setups.
  • Env-var overrides — update_from_env("MYAPP_") reads MYAPP_MODEL__LR=0.001-style env vars through the same override engine. Composes naturally with YAML → env → CLI precedence.
  • Schema-aware --help — python script.py --help prints every overridable field with its type, default, current value, and docstring. Literal / Enum choices are surfaced inline.
  • Shell tab completion — onefig install-python-completion <shell> enables TAB completion of every overridable key for any onefig script invoked via python. Supports bash, zsh, and fish.
  • CLI / env override shortcuts — on the command line and in env vars, lr (or any trailing subpath like model.lr) resolves to its full path when unambiguous; ambiguous keys raise with a clear message. In Python code, always use the full attribute path.
  • Round-trip serialization — cfg.save_yaml() ↔ Cfg.load(), and cfg.to_flat_dict() ↔ Cfg.from_flat_dict().
  • Config diff — cfg.diff(other) and cfg.diff_from_defaults() surface leaf-level changes as {path: (old, new)}, with a MISSING sentinel for cross-schema gaps. Handy for run logs and PR-style "what changed" output.
  • Swappable components: tagged_union(...) lets a field hold any of several variant configs, picked by a name tag in YAML, CLI or env. The tag is a class attribute derived from the class name (MCARConfig → mcar), so variant fields are only real settings.
  • Field traits: attach your own typed objects to fields with Field(default, *traits), find them anywhere in the tree with cfg.find(Kind), and fill values in with cfg.replace({...}).
  • Field docs: field_docs(cls) reads every field's docstring, for configs and dataclasses, and describe_fields(obj) shows them as a Markdown table in a notebook.
  • Recursive freeze — cfg.freeze() makes the whole tree immutable.
  • Tree display — cfg.display() prints the config as an ASCII tree.
  • Auto config name — cfg.config_name is set from the YAML filename and available everywhere (run dirs, log lines, default tree titles).
  • Auto commit hash — cfg.commit_hash captures the running code's git HEAD on construction (best-effort; None when unavailable).

Documentation

Full documentation: bviggiano.github.io/onefig

License

MIT

But my lord, there is no Frodo    Gandalf nod    They're taking the hobbits to Isengard

Metadata

Release files for onefig 0.1.4

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

Source distribution (sdist)

Source distribution for onefig 0.1.4
File Size Uploaded Provenance Actions
onefig-0.1.4.tar.gz 81.7 kB With provenance Details for onefig-0.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for onefig 0.1.4
File Interpreter ABI Platform Actions
onefig-0.1.4-py3-none-any.whl Python 3 none any Details for onefig-0.1.4-py3-none-any.whl

Total release size: 139.3 kB

Release files / onefig-0.1.4.tar.gz

Download URL onefig-0.1.4.tar.gz
Size 81.7 kB
Tags Source
SHA-256 checksum
How to use checksums
80887a47c257c8759c39df1ff891107cc92a268814caf58ed369e342292193b1
BLAKE2b-256 checksum
How to use checksums
409303c7b0e05cfa22397b4d366f51b3f1071e3e87a056679bbb7cf1ebeae7b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Release files / onefig-0.1.4-py3-none-any.whl

Download URL onefig-0.1.4-py3-none-any.whl
Size 57.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ec9726f7e0dbf862c9058ef2087f3bd2aad2cc7d10afa9a76116ec0effd3c601
BLAKE2b-256 checksum
How to use checksums
5278c464fa76654a5b2c9ba9709e310d935d41f5f4ac4e71e4965d2b7b7d6d3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Security for onefig 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for onefig-0.1.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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