Skip to main content

Eafig

Manage your hyperparameters from the outside.

Installation

pip install eafig

Requires Python ≥ 3.12.

Quick Start

import eafig
from eafig import configclass

@configclass("training")
class TrainingConfig:
    a: int = 1
    c: float = 1.0

@configclass(name="model")
class ModelConfig:
    x: str = "hello"
    y: str = "world"


# Load from file, then CLI — later calls win
eafig.load("config/default.yaml")
eafig.from_cli()

# Save to file
eafig.save("config/saved_config.yaml")

# Instantiate — values come from file/CLI or defaults
training = TrainingConfig()
model = ModelConfig()

Core ideas

Group-only layers

There is no "root config". Every config class is a named group registered with @configclass("path"). The path is dot-separated for nesting:

@configclass("model")
class ModelConfig:
    hidden_dim: int = 256

@configclass("model.optimizer")
class OptimizerConfig:
    lr: float = 1e-3

Every field needs a default

Fields must declare a default value (or a default_factory). Registering a field without one raises a TypeError:

@configclass("model")
class ModelConfig:
    hidden_dim: int = 256   # OK
    # lr: float            # TypeError: must provide a default value

Config loading order

defaults  <  file (load)  <  CLI (from_cli)

Each layer overrides the one before it. Among load() / from_cli() calls, later calls win.

keep_cli

A later load() normally overrides CLI values. Pass keep_cli=True to keep CLI on top:

eafig.from_cli()
eafig.load("config.yaml", keep_cli=True)  # CLI stays above file

load_by_cli

Load a config file whose path comes from a command-line flag:

# python app.py --config config.yaml
eafig.load_by_cli("config")

The flag is registered as the single root schema field, remains in the stored configuration, and is included by save(). Because the root schema may only be registered once, load_by_cli() may only be called once per process when the flag is present; a second call raises ValueError.

CLI overrides

--model.hidden_dim 1024 --model.optimizer.lr 1e-3

A flag with no value is True; dotted keys nest. An explicitly supplied empty argument remains an empty string:

eafig.from_cli(["--debug", "--name", ""])
assert eafig.get("debug") is True
assert eafig.get("name") == ""

Unknown keys (allow_dynamic_children)

By default a config group rejects keys that are not declared fields or child groups. The rejection happens when the config is read — when you instantiate the group or call save():

@configclass("model")
class ModelConfig:
    hidden_dim: int = 256

eafig.load("config.yaml")   # config.yaml has model.typo_key → loaded without error
model = ModelConfig()       # KeyError: Invalid key(s) {'typo_key'}

Set allow_dynamic_children=True to tolerate extra keys (they are ignored):

@configclass("model", allow_dynamic_children=True)
class ModelConfig:
    hidden_dim: int = 256

Schema registration may happen after load(). Loading performs structural validation for schema paths already known at that time; unknown-key validation is deferred until a group is instantiated or the configuration is saved.

Hidden groups

@configclass("api", hidden=True)
class ApiConfig:
    secret_key: str = "..."

Hidden groups are excluded from save() and from recursive reads by default.

Frozen groups

@configclass("model", frozen=True)
class ModelConfig:
    hidden_dim: int = 256

m = ModelConfig()          # OK — uses defaults
m.hidden_dim = 1024        # FrozenInstanceError

Runtime get

value = eafig.get("model.hidden_dim")        # 256
value = eafig.get("missing.key", default=0)  # 0

API reference

API Description
@configclass(name, *, frozen=False, hidden=False, allow_dynamic_children=False) Register a dataclass as a config group
eafig.load(path=None, keep_cli=False) Load a YAML file or file-like object
eafig.from_cli(args=None) Parse CLI args (default: sys.argv[1:])
eafig.load_by_cli(flag, keep_cli=False) Load a file path taken from a CLI flag
eafig.save(path, sort_keys=True) Save the config to YAML
eafig.config Access the current complete configuration as a dictionary
eafig.get(key, default=None) Get a single value (dot notation)

Examples

See examples/.

License

MIT

Metadata

Release files for eafig 2.0.1

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

Source distribution (sdist)

Source distribution for eafig 2.0.1
File Size Uploaded Provenance Actions
eafig-2.0.1.tar.gz 24.1 kB With provenance Details for eafig-2.0.1.tar.gz

Built distribution (wheel)

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

Total release size: 35.1 kB

Release files / eafig-2.0.1.tar.gz

Download URL eafig-2.0.1.tar.gz
Size 24.1 kB
Tags Source
SHA-256 checksum
How to use checksums
16265309fd7907be50081d51bba06ee77a49c1850998b391bf3fb8ca0e95a9f9
BLAKE2b-256 checksum
How to use checksums
92a7edd93c7f046780bcf60be585d10eb9d1269b80a657ab2fda1368f6df259d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 29, 2026.

Transparency log

Release files / eafig-2.0.1-py3-none-any.whl

Download URL eafig-2.0.1-py3-none-any.whl
Size 11.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3b87addb9bfe898bbeb3a3d9f28ae34dbcacb2274e330250fe1985b1de647cc0
BLAKE2b-256 checksum
How to use checksums
63afc2c2ec5e0e67fd28a5b08021247b018d95b00f60e241f78d580abc1c102b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 29, 2026.

Transparency log

Security for eafig 2.0.1

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 eafig-2.0.1.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 Aug 29, 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