hydra-typing
Typed dataclass configs for Hydra — one import, zero boilerplate.
Your @hydra.main function receives an untyped DictConfig. With hydra-typing, it receives your @dataclass instance instead — full IDE autocompletion, mypy/pyright checking, and all Python types supported (Literal, Enum, Union, Path, datetime, nested dataclasses, List[Dataclass], Dict[str, Dataclass], etc.).
All Hydra features work unchanged — defaults: groups, ${} interpolation, CLI overrides, --multirun, sweepers, launchers, output management.
Install
pip install hydra-typing
One dependency: hydra-core.
Usage
Transparent patch (recommended) — keep your @hydra.main:
import hydra
import hydra_typing; hydra_typing.patch()
@hydra.main(config_path="conf", config_name="config", version_base=None)
def main(cfg: TrainConfig) -> None:
# cfg is typed! No DictConfig, no OmegaConf.
print(cfg.model.hidden_dim) # IDE autocompletion works
Explicit decorator:
from hydra_typing import hydra_main
@hydra_main(config_path="conf", config_name="config")
def main(cfg: TrainConfig) -> None:
...
Programmatic (notebooks, scripts):
from hydra_typing import load_config
cfg = load_config(TrainConfig, config_name="base",
overrides=["model=large", "lr=0.001"])
Features
- Typed configs — real
@dataclassinstances, notDictConfig - Full Python type support —
Literal,Enum,Union,Path,datetime, nested dataclasses,List[Dataclass],Dict[str, Dataclass] HydraConfig— typed access to Hydra's built-in runtime config (run.dir,job.name,overrides.task, etc.)_target_/instantiate— standard Hydra_target_pattern works as a typed fieldto_omegaconf()— 100% compatibility fallback: convert typed config back to OmegaConfDictConfig- Non-invasive — functions without type annotations pass through unchanged
- Single file —
hydra_typing.py, ~700 lines, one dependency
Complex nested configs
@dataclass
class LayerConfig:
type: Literal["attention", "mlp"] = "attention"
dim: int = 256
@dataclass
class TrainConfig:
layers: List[LayerConfig] = field(default_factory=lambda: [
LayerConfig(type="attention", dim=256),
LayerConfig(type="mlp", dim=512),
])
CLI overrides for nested collections:
# List elements by index
python train.py model.layers.0.dim=1024
# Dict elements by key
python train.py model.heads.attention.dim=512
# Append to list
python train.py +model.layers.2.type=conv +model.layers.2.dim=512
_target_ / instantiate
@dataclass
class LoRAConfig:
_target_: str = "__main__.LoRAConfig"
rank: int = 8
alpha: int = 16
def __post_init__(self):
self.scaling = self.alpha / self.rank
# Deferred instantiate via OmegaConf round-trip (100% compat)
import hydra.utils
oc = hydra_typing.to_omegaconf(cfg.model.lora)
lora = hydra.utils.instantiate(oc)
HydraConfig — typed built-in config
@dataclass
class TrainConfig:
hydra: HydraConfig = field(default_factory=HydraConfig)
# Auto-populated:
cfg.hydra.run.dir # "outputs/2026-08-05/15-24-20"
cfg.hydra.job.name # "train"
cfg.hydra.overrides.task # ["model=large", "lr=0.001"]
vs Hydra
| hydra | hydra-typing | |
|---|---|---|
| Config object | DictConfig |
typed @dataclass |
| IDE autocomplete | limited | full |
Literal, Union |
unsupported | supported |
Path, datetime |
unsupported | supported |
| YAML composition | yes | yes (unchanged) |
| CLI overrides | yes | yes (unchanged) |
--multirun |
yes | yes (unchanged) |
_target_ / instantiate |
yes | yes |
| Output management | yes | yes (unchanged) |
API
hydra_typing.patch() # make @hydra.main typed (call once)
hydra_typing.hydra_main(...) # explicit decorator
hydra_typing.load_config(...) # programmatic (notebooks)
hydra_typing.to_plain(cfg) # dataclass → dict
hydra_typing.to_omegaconf(cfg) # dataclass → OmegaConf DictConfig (100% compat)
About
This project was built to scratch a personal itch: I wanted Hydra's YAML composition and CLI, but with real typed configs I can trust my IDE with. I'm not yet writing the actual training code — but I want the config management to be clean from day one.
This code was written entirely by Claude Code (Anthropic) using the DeepSeek API. I acted as the product manager — specifying what the library should do, reviewing the output, and iterating. The implementation, tests, examples, and documentation were all generated by Claude.
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hydra_typing-0.2.0.tar.gz.
File metadata
- Download URL: hydra_typing-0.2.0.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a73e16ef26d77b47f2d3ece6185a09c456c9b8addb8a3b890d9e163e414dc235
|
|
| MD5 |
d7192020dc08ca19e99c4befb90b93bc
|
|
| BLAKE2b-256 |
1203ee781a1dbf3f6c58488f8fa89fecac11a815138618788102eb33c046011b
|
File details
Details for the file hydra_typing-0.2.0-py3-none-any.whl.
File metadata
- Download URL: hydra_typing-0.2.0-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54e81cc2194a48dd59003886f06af97d8ffedacfc69751b4c4b5ee2fcdb90f36
|
|
| MD5 |
d7391573808c743294d9954109f80f2c
|
|
| BLAKE2b-256 |
4a9573cbc8516d0a00340dcc5902b9e7a22dac651d7ec892723198766581f956
|