Skip to main content

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

Project description

EzConfy logo

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

PyPI version License


Why EzConfy?

ML projects constantly deal with configuration: learning rates, model parameters, dataset options, augmentation pipelines. EzConfy gives you typed, validated configs with automatic object wiring — without the complexity of a full framework like Hydra.

from ezconfy import ConfigBuilder

cfg = ConfigBuilder.from_files(config_paths="config.yaml", schema_path="schema.yaml")
print(cfg.training.batch_size)  # validated, typed access

What you get

Feature Description
Pydantic validation Type checking with clear error messages
Schema-aware casting Strings become Path objects, etc. — before constructors run
Dynamic instantiation Construct any Python class from YAML via _target_type_
Placeholders ${key}, attribute access, method calls, arithmetic
Multi-file merge Split configs across files, override per experiment
Code generation Generate Pydantic models for editor autocompletion

Installation

pip install ezconfy

Requires Python 3.11+.

Quick Start

config.yaml

lr: 0.001
batch_size: 32
data_path: ./data

schema.yaml

lr: float
batch_size: int
data_path: pathlib:Path

train.py

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

Schema

A schema file describes the expected shape and types of your configuration:

types:
  OptimizerType:
    - adam
    - sgd
    - rmsprop

schema:
  model:
    hidden_dims: list[int]
  training:
    batch_size: int = 32
    num_epochs: int = 10
    shuffle: bool = true
    dropout: float?
    optimizer: OptimizerType

If no types are needed, the entire YAML is treated as the root schema (no schema: wrapper required).

Supported type syntax
Syntax Meaning
int, float, str, bool Primitive types
type? Optional (defaults to None)
type = value Type with default
list[T] List of T
A | B Union type
[a, b, c] Enum
Child < Parent Model inheritance
pathlib:Path External type (import path)
/path/to/file.py:ClassName External type (file path)

Object Instantiation

Construct Python objects directly from config using _target_type_:

dataset:
  _target_type_: mypackage.data:MyDataset
  _init_args_:
    num_classes: 100
    root: /data

Use _init_method_ for alternative constructors (e.g. from_pretrained):

encoder:
  _target_type_: mypackage.models:BertEncoder
  _init_method_: from_pretrained
  _init_args_:
    model_name: bert-base-uncased

Placeholders & Expressions

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

lr: 0.001
warmup_lr: ${lr * 10}                       # arithmetic

num_classes: 10

dataset:
  _target_type_: mypackage.data:MyDataset
  _init_args_:
    num_classes: ${num_classes}               # scalar reference

model:
  _target_type_: mypackage.models:Classifier
  _init_args_:
    in_features: ${dataset.num_classes}       # attribute access
    params: ${encoder.parameters()}           # method call

Objects are instantiated in topological order based on their dependencies — forward references work automatically.

Multi-file Configs & Overrides

Pass multiple files — they are deep-merged in order (later files win on conflicts):

cfg = ConfigBuilder.from_files(
    config_paths=["base.yaml", "experiment.yaml"],
)

Apply programmatic overrides on top:

cfg = ConfigBuilder.from_files(
    config_paths="config.yaml",
    overrides={"training": {"batch_size": 64}},
)

Code Generation CLI

Generate a Pydantic model file from a schema for editor autocompletion and static analysis:

ezconfy generate schema.yaml -o models.py

Documentation

Full documentation: alessioarcara.github.io/EzConfy

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

ezconfy-0.1.11.tar.gz (121.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ezconfy-0.1.11-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file ezconfy-0.1.11.tar.gz.

File metadata

  • Download URL: ezconfy-0.1.11.tar.gz
  • Upload date:
  • Size: 121.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for ezconfy-0.1.11.tar.gz
Algorithm Hash digest
SHA256 3a4e443d9e2b8065ca0f81def9e3173ab2d468ab951de88e968c8918c5dbcdfb
MD5 4335df65a867a799163a672012f427f0
BLAKE2b-256 0e970fc27902fd1b96eeda3be2959f98e18758cf60815cf4251b8dc791bcfa11

See more details on using hashes here.

File details

Details for the file ezconfy-0.1.11-py3-none-any.whl.

File metadata

  • Download URL: ezconfy-0.1.11-py3-none-any.whl
  • Upload date:
  • Size: 18.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for ezconfy-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 e90b41b997538a4753cccb2260cc31e18c1e04dcb105204a02526986eabad2dd
MD5 b1c8dfe8df7ffbb6a805d3b61cdf36ba
BLAKE2b-256 4920c72d4d6e67ac471ccdd1a04f6655e3ded57568b029cd33f273684228a1f6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page