How to get a Hydra config without using @hydra.main()

Use the Compose API:

from hydra import compose, initialize
from omegaconf import OmegaConf

with initialize(version_base=None, config_path="conf", job_name="test_app"):
    cfg = compose(config_name="config", overrides=["db=mysql", "db.user=me"])

print(OmegaConf.to_yaml(cfg))

This will only compose the config and will not have side effects like changing the working directory or configuring the Python logging system.

Leave a Comment