Manage your hyperparameters more easily.
Project description
Eafig
Manage your hyperparameters from the outside.
Installation
pip install eafig
Requires Python ≥ 3.12.
Quick Start
import eafig
from eafig import rootconfig, configclass
@rootconfig
class MyConfig:
a: int
c: float = 1.0
@configclass(name="sub_config")
class MySubConfig:
x: str = "hello"
y: str = "world"
# Load from file, then CLI (later calls have higher priority)
eafig.load("config/default.yaml")
eafig.from_cli()
# Constructor args take highest priority
config = MyConfig(a=5)
sub = MySubConfig()
# Save back to a file
eafig.save("config/saved_config.yaml")
Config Loading Order
Later sources win:
file (load) < CLI (from_cli) < constructor args
Load from YAML
# config/default.yaml
a: 12
sub_config:
x: from_file
y: from_file
Override via CLI
python main.py --a 42 --sub_config.x cli_value
Override via constructor
config = MyConfig(a=5) # 5 wins over both file and CLI
Nested Configs
@configclass(name="model")
class ModelConfig:
hidden_dim: int = 256
num_layers: int = 3
@configclass(name="training")
class TrainingConfig:
lr: float = 1e-3
batch_size: int = 32
@rootconfig
class Root:
seed: int = 42
Corresponding YAML:
seed: 42
model:
hidden_dim: 512
num_layers: 6
training:
lr: 5e-4
batch_size: 64
CLI override with dot notation: --model.hidden_dim 1024 --training.lr 1e-3
Strict Mode
Enabled by default. Unknown keys in the loaded config raise KeyError at instantiation time.
@rootconfig(strict=True) # default
class MyConfig:
a: int = 1
If a YAML file contains typo_key: oops, then MyConfig() raises:
KeyError: Unknown configuration key(s) in root config: ['typo_key']. Known keys: ['a'].
Set strict=False to allow extra keys:
@rootconfig(strict=False)
class MyConfig:
a: int = 1
Each config class controls its own strict mode independently.
Frozen Configs
@rootconfig(frozen=True)
class MyConfig:
a: int = 42
config = MyConfig() # OK
config = MyConfig(a=5) # TypeError: cannot override frozen config
config.a = 100 # FrozenInstanceError
API
| API | Description |
|---|---|
@rootconfig(frozen=False, strict=True) |
Decorate a dataclass as root config |
@configclass(name, frozen=False, hidden=False, strict=True) |
Decorate a dataclass as child config |
eafig.load(path, keep_cli=False) |
Load config from YAML file |
eafig.from_cli(args=None) |
Parse CLI arguments (default: sys.argv[1:]) |
eafig.save(path) |
Save current config to YAML |
Examples
See the examples/ directory.
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file eafig-1.1.1.tar.gz.
File metadata
- Download URL: eafig-1.1.1.tar.gz
- Upload date:
- Size: 18.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b328afd7577e74a0be01c740d194f84e9d6924dd9bf91bc537dcaa5af664b39
|
|
| MD5 |
e8221a0cf4d9eb979d71630e0c38b029
|
|
| BLAKE2b-256 |
8859484faeb37b7cd74f6e6c6241dd825de0b37e8765d59e908d8e2d139b34f3
|
Provenance
The following attestation bundles were made for eafig-1.1.1.tar.gz:
Publisher:
publish.yml on MugeTong/eafig
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
eafig-1.1.1.tar.gz -
Subject digest:
0b328afd7577e74a0be01c740d194f84e9d6924dd9bf91bc537dcaa5af664b39 - Sigstore transparency entry: 1753987975
- Sigstore integration time:
-
Permalink:
MugeTong/eafig@2056cea1ec804d86b5e3cc6fa88dba9056441db3 -
Branch / Tag:
refs/tags/v1.1.1 - Owner: https://github.com/MugeTong
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2056cea1ec804d86b5e3cc6fa88dba9056441db3 -
Trigger Event:
release
-
Statement type:
File details
Details for the file eafig-1.1.1-py3-none-any.whl.
File metadata
- Download URL: eafig-1.1.1-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0dc1981ba88783aa830a845bbd964cc572d11b1c3189a9c20796bf11c3b492a
|
|
| MD5 |
a5aa8ec09006b9582976e5d0d5357a17
|
|
| BLAKE2b-256 |
e9ddb6f76ac0e3b115333c0195f572dc98f452b78d98a3e219e161ef1e1087d4
|
Provenance
The following attestation bundles were made for eafig-1.1.1-py3-none-any.whl:
Publisher:
publish.yml on MugeTong/eafig
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
eafig-1.1.1-py3-none-any.whl -
Subject digest:
c0dc1981ba88783aa830a845bbd964cc572d11b1c3189a9c20796bf11c3b492a - Sigstore transparency entry: 1753988048
- Sigstore integration time:
-
Permalink:
MugeTong/eafig@2056cea1ec804d86b5e3cc6fa88dba9056441db3 -
Branch / Tag:
refs/tags/v1.1.1 - Owner: https://github.com/MugeTong
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2056cea1ec804d86b5e3cc6fa88dba9056441db3 -
Trigger Event:
release
-
Statement type: