Metadata-Version: 2.4
Name: nematocyte
Version: 0.4.0
Summary: Configuration for Python programs, as a tree of dataclasses filled from YAML or JSON5 files and the command line
Author: Thomas M Kehrenberg
Author-email: Thomas M Kehrenberg <tmke8@posteo.net>
License-Expression: MIT
License-File: LICENSE
Requires-Dist: pydantic>=2.12
Requires-Dist: ruamel-yaml>=0.18
Requires-Dist: typing-extensions>=4.16
Requires-Dist: json5>=0.17 ; extra == 'json5'
Requires-Dist: optuna>=4 ; extra == 'optuna'
Requires-Dist: submitit>=1.5 ; extra == 'submitit'
Requires-Python: >=3.14
Provides-Extra: json5
Provides-Extra: optuna
Provides-Extra: submitit
Description-Content-Type: text/markdown

# nematocyte

A configuration library for Python programs: a replacement for Hydra with
fewer features and more focus on usability. The config is a tree of stdlib
dataclasses (or `TypedDict`s), filled from YAML (or JSON5) files and
command-line overrides.

```python
from dataclasses import dataclass, field
from typing import Annotated

from pydantic import Discriminator, Tag

import nematocyte


@dataclass(kw_only=True)
class Fcn:
    """Fully-connected network."""

    num_hidden: int = field(default=1, doc="Number of hidden layers.")


@dataclass(kw_only=True)
class Cnn:
    """Convolutional network."""

    kernel_size: int = field(default=5, doc="Kernel size of the convolutions.")


@dataclass(kw_only=True)
class Config:
    """Train a model."""

    model: Annotated[
        Annotated[Fcn, Tag("fcn")] | Annotated[Cnn, Tag("cnn")],
        Discriminator(nematocyte.pick),
    ] = field(default_factory=Fcn, doc="The model architecture.")
    seed: int = field(default=42, doc="Random seed.")


@nematocyte.main(Config, config_path="configs")
def main(config: Config) -> None:
    print(config)


if __name__ == "__main__":
    main()
```

```bash
python main.py model=cnn model.kernel_size=3 seed=1
python main.py --help
python main.py --multirun seed=1,2,3
```

- [`example/`](example/) is a complete project with an annotated README.
- [`design/`](design/) holds the design documents, which are the
  specification.
- [`DIFFERENCES.md`](DIFFERENCES.md) lists what works differently from
  Hydra, for someone who knows it.

## Installing

nematocyte needs Python 3.14 or later.

```bash
uv add nematocyte
uv add 'nematocyte[submitit]'  # for the SLURM launcher
uv add 'nematocyte[optuna]'  # for the Optuna sweeper
uv add 'nematocyte[json5]'  # for config files in JSON5
```

## Developing

```bash
uv run ruff check
uv run ruff format --check
uv run ty check
uv run pytest
```
