Skip to content

Home

EzConfy logo EzConfy logo

YAML-based configuration with Pydantic validation and dynamic object instantiation.

PyPI version License


The Problem

If you have ever written a Python project — especially in machine learning — you have probably dealt with configuration: learning rates, file paths, model parameters, dataset options. At first you hard-code them, then you move them to a dictionary, then maybe a YAML file. But soon you run into problems:

  • No validation


    Misspell a key (lerning_rate instead of learning_rate) and nothing complains — the value is silently ignored. Pass a string where an integer is expected and you get a crash deep in your training loop.

  • No typing


    Every value is a raw string or number. If your code expects a Path object, you have to remember to convert it yourself.

  • No wiring


    You load config values but still have to manually write MyDataset(num_classes=config["num_classes"]) everywhere.

  • Too much boilerplate


    As configs grow, the glue code between "reading a YAML file" and "having usable objects" keeps expanding.

EzConfy eliminates all of this. Write a YAML config, optionally define a schema, and get back fully instantiated, validated Python objects — ready to use.


Key Features

  • YAML config files


    Human-readable, easy to diff and version-control.

  • Pydantic validation


    Define a schema and get automatic type checking with clear error messages.

  • Schema-aware type casting


    Values are cast to schema types before constructors run — strings become Path objects automatically.

  • Dynamic object instantiation


    Construct any Python class from config using _target_type_.

  • Placeholders & expressions


    Reference other values with ${key}, including attribute access, method calls, and arithmetic.

  • Multi-file deep merge


    Split configs across files, override per experiment — later files win.

  • Code generation CLI


    Generate Pydantic model files from your schema for editor autocompletion.


Installation

pip install ezconfy

Requirements

Python 3.11 or later.


Quick Example

lr: 0.001
batch_size: 32
data_path: ./data
lr: float
batch_size: int
data_path: pathlib:Path
from ezconfy import ConfigBuilder

cfg = ConfigBuilder.from_files(
    config_paths="config.yaml",
    schema_path="schema.yaml",
)

print(cfg.lr)          # 0.001 (float)
print(cfg.batch_size)  # 32 (int)
print(cfg.data_path)   # PosixPath('data') — automatically cast

Three files, three lines of Python, and you get validated, typed configuration.


What's Next?