Metadata-Version: 2.4
Name: eafig
Version: 1.1.0
Summary: Manage your hyperparameters more easily.
Project-URL: Homepage, https://github.com/MugeTong/eafig
Project-URL: Issues, https://github.com/MugeTong/eafig/issues
Author-email: MugeTong <here5320@gmail.com>
License: MIT License
        
        Copyright (c) 2026 MugeTong
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Requires-Python: >=3.12
Requires-Dist: omegaconf
Requires-Dist: pyyaml
Description-Content-Type: text/markdown

# Eafig

Manage your hyperparameters from the outside.

## Installation

```bash
pip install eafig
```

Requires Python ≥ 3.12.

## Quick Start

```python
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

```yaml
# config/default.yaml
a: 12
sub_config:
  x: from_file
  y: from_file
```

### Override via CLI

```bash
python main.py --a 42 --sub_config.x cli_value
```

### Override via constructor

```python
config = MyConfig(a=5)  # 5 wins over both file and CLI
```

## Nested Configs

```python
@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:

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

```python
@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:

```python
@rootconfig(strict=False)
class MyConfig:
    a: int = 1
```

Each config class controls its own strict mode independently.

## Frozen Configs

```python
@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/](examples/) directory.

## License

MIT
