Skip to main content

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

Project description

ezconfy logo

Why ezconfy?

EzConfy is designed for ML projects that want typed, validated configs with automatic object wiring - without the complexity of a full framework like Hydra.

Installation

pip install ezconfy

Quick Start

Define a schema and a config file, then load them:

from ezconfy import ConfigBuilder

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

Schema

A schema file describes the expected shape and types of your configuration. It can define custom types and the root structure:

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

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)

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

Object Instantiation

ezconfy can instantiate Python objects directly from config using _target_type_:

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

Use _init_method_ to call an alternative constructor (e.g. from_pretrained):

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

Placeholder Injection

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

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, so 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:

ezconfy generate schema.yaml output.py

This produces a standalone .py file with BaseModel classes matching the schema, useful for editor autocompletion and static analysis.

Requirements

  • Python 3.11+

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.5.tar.gz (105.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.5-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ezconfy-0.1.5.tar.gz
  • Upload date:
  • Size: 105.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.5.tar.gz
Algorithm Hash digest
SHA256 bef1bdde674b81b69ac20868bd91c912faa30ca92e369639b95adb6ad3d0fcf1
MD5 d0fc6dc23bd017da17617729cca806d7
BLAKE2b-256 a7fb06a1773faaf3944d8d1a85c3bd6e3f521f4583dbe3e9d040a3b2ec1fb55e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ezconfy-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 16.6 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 69d4ae458e21ec7578727f09b1f7a90580ba3ee6fa5111b32b73dea1b5d85457
MD5 c70a6f74f0ca75e50c6826bde2b3d25f
BLAKE2b-256 e63924ff61b6b86c044f35cb40b04abcda522e3caeb3929e65ba0ca5072afc66

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