onefig
pip install 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
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_clifor quick scripts, orupdate_from_argsfor custom argparse setups. - Env-var overrides —
update_from_env("MYAPP_")readsMYAPP_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 --helpprints every overridable field with its type, default, current value, and docstring.Literal/Enumchoices are surfaced inline. - Shell tab completion —
onefig install-python-completion <shell>enables TAB completion of every overridable key for any onefig script invoked viapython. Supportsbash,zsh, andfish. - CLI / env override shortcuts — on the command line and in env vars,
lr(or any trailing subpath likemodel.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(), andcfg.to_flat_dict()↔Cfg.from_flat_dict(). - Config diff —
cfg.diff(other)andcfg.diff_from_defaults()surface leaf-level changes as{path: (old, new)}, with aMISSINGsentinel 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 anametag 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 withcfg.find(Kind), and fill values in withcfg.replace({...}). - Field docs:
field_docs(cls)reads every field's docstring, for configs and dataclasses, anddescribe_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_nameis set from the YAML filename and available everywhere (run dirs, log lines, default tree titles). - Auto commit hash —
cfg.commit_hashcaptures the running code'sgit HEADon construction (best-effort;Nonewhen unavailable).
Documentation
Full documentation: bviggiano.github.io/onefig
License
MIT
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)
| 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)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| 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 logRelease 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 logSecurity 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.
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 logA 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.