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
    tasks: list[str] = ["train", "evaluate"]  # mutable defaults are supported
    # lr: float            # TypeError: must provide a default value

@configclass automatically gives list and dict defaults an independent default_factory. You can still use dataclasses.field explicitly when a custom factory is needed.

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", keep_cli=False)  # file wins conflicts (default)
# eafig.load_by_cli("config", keep_cli=True) # CLI wins conflicts

load_by_cli() always reads all CLI arguments. keep_cli only decides precedence when a key appears both on the command line and in the selected file.

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.2

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.2
File Size Uploaded Provenance Actions
eafig-2.0.2.tar.gz 25.3 kB With provenance Details for eafig-2.0.2.tar.gz

Built distribution (wheel)

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

Total release size: 37.3 kB

Release files / eafig-2.0.2.tar.gz

Download URL eafig-2.0.2.tar.gz
Size 25.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f6607f47563efebc66ec3c529750e0a84ea0fd477341d813b144e2a8e8368a7b
BLAKE2b-256 checksum
How to use checksums
9d707984e3eb62ed0a947e2f2e65233fc74a4ec4d54461f8787358a755c4dded
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 30, 2026.

Transparency log

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

Download URL eafig-2.0.2-py3-none-any.whl
Size 11.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9c5619bbf5a33c8a0efd5ef7c057a5afde1cb535811827cfda91e87098f245bd
BLAKE2b-256 checksum
How to use checksums
e06217b6cf99e2d8b9f3249135653aeeac572b95ee4af55470111303035fe9a9
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 30, 2026.

Transparency log

Security for eafig 2.0.2

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.2.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 30, 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