Skip to main content

hydrette

Lightweight Hydra-style configuration management for Python.

Core dependency: PyYAML. Optional: tomli (for TOML on Python < 3.11).

Features

  • Config compositiondefaults list + config groups, like Hydra
  • Variable interpolation${key.path}, ${env:VAR}, ${now:%Y-%m-%d}
  • CLI overrideskey=val, +key=val (add), ++key=val (force), ~key (delete)
  • @main decorator — entrypoint with automatic CLI parsing
  • Structured config — dataclass schema validation (warning / strict)
  • instantiate() — build objects from _target_ configs
  • Dot & subscript accesscfg.db.host == cfg["db"]["host"]
  • YAML & TOML.yaml, .yml, .toml config files; mixed-format projects supported

Quick Start

Installation

pip install -e .

Project structure

conf/
├── config.yaml          # root config
├── db/
│   ├── mysql.yaml
│   └── postgres.yaml
└── model/
    ├── resnet.yaml
    └── vgg.yaml

Root config (conf/config.yaml)

defaults:
  - db: mysql
  - model: resnet

app_name: demo
db_url: ${db.host}:${db.port}

Group config (conf/db/mysql.yaml)

host: localhost
port: 3306

Using compose()

from hydrette import compose

cfg = compose("conf")
print(cfg.db.host)     # "localhost"
print(cfg.db_url)      # "localhost:3306"

CLI overrides

from hydrette import compose

cfg = compose("conf", overrides=["db=postgres", "model.lr=0.001"])

From command line with @main:

python app.py -- db=postgres model.lr=0.001

@main decorator

from hydrette import main, Config

@main(config_path="conf")
def app(cfg: Config) -> None:
    print(cfg.db.host)

if __name__ == "__main__":
    app()

Variable interpolation

Syntax Description
${key.path} Reference another config value
${env:VAR} Environment variable
${env:VAR,default} Env var with default
${now:%Y-%m-%d} Current time (strftime)
${${prefix}_lr} Nested interpolation

Custom resolvers

from hydrette import register_resolver

register_resolver("greet", lambda name: f"Hello, {name}!")

# In YAML: message: ${greet:World}

Schema validation

from dataclasses import dataclass
from hydrette import register_schema, validate_config, Config

@dataclass
class TrainCfg:
    lr: float = 0.01
    epochs: int = 10

register_schema("train", TrainCfg)

cfg = compose("conf")
validate_config(cfg)          # warning mode (default)
validate_config(cfg, strict=True)  # raise on errors

instantiate()

from hydrette import instantiate, Config

cfg = Config({
    "_target_": "mymodule:MyClass",
    "x": 1,
    "y": 2,
})
obj = instantiate(cfg)

_self_ position

In the defaults list, _self_ controls where the root config's own keys are merged into the composition chain:

  • Explicit: place _self_ wherever you want
  • Implicit (default): _self_ is appended at the end, so root keys override group keys at the same path

Group configs are namespaced under their group name: db/mysql.yamlcfg.db.host, not cfg.host.

Override syntax

Syntax Meaning
key=val Set existing key
+key=val Add new key (error if exists)
++key=val Force set (add or overwrite)
~key Delete key
db=postgres Switch config group

CLI flags

Flag Description
--quiet Suppress loading tree output
--help Print config preview and usage
HYDRETTE_QUIET=1 Environment variable alternative

File formats

hydrette supports both YAML (.yaml / .yml) and TOML (.toml) config files. You can even mix formats within a project — e.g. a YAML root with TOML group configs.

Extension probing

When config_name is given without an extension, hydrette probes in order: .yaml.yml.toml. If multiple files match, an ambiguity error is raised.

# Only config.toml exists → auto-detected
python app.py

# Explicit TOML root
python app.py  # compose("conf", config_name="config.toml")

TOML defaults syntax

YAML uses - db: mysql for defaults. In TOML, use inline tables:

defaults = [{ db = "mysql" }]

Override directives in TOML:

# Quoted key (same as YAML "override db: postgres")
defaults = [{ db = "mysql" }, { "override db" = "postgres" }]

# Structured form (cleaner)
defaults = [
  { db = "mysql" },
  { group = "db", name = "postgres", override = true },
]

Installing TOML support

Python 3.11+ includes tomllib in the standard library — no extra install needed.

For Python 3.9–3.10:

pip install hydrette[toml]

If you load a .toml file without the dependency installed, hydrette will show a clear error message with the install command.

License

MIT

Release files for hydrette 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hydrette 0.1.0
File Size Uploaded
hydrette-0.1.0.tar.gz 31.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hydrette 0.1.0
File Interpreter ABI Platform
hydrette-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 53.6 kB

Release files / hydrette-0.1.0.tar.gz

Download URL hydrette-0.1.0.tar.gz
Size 31.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b4202e7f47a613d6849d6ccebaac87856bea16d9c6e2cef22fc60c7f6bb05648
BLAKE2b-256 checksum
How to use checksums
2ab349b8c15cbdfd0649fcdfa0a53d9dec634d373b467749867a396b066233ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.9

Release files / hydrette-0.1.0-py3-none-any.whl

Download URL hydrette-0.1.0-py3-none-any.whl
Size 22.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
11b62e4ad0bce37073bee57456c1a9c35b3aa16cf29cb9f6c1ac1b02a1c5ba73
BLAKE2b-256 checksum
How to use checksums
26cffccc177fe6ef457a04fac3330de95b4affc50ab7e0a23e8ce3d5d9c67375
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page