Skip to main content
Version: 0.11

Config groups

This is the most important concept in Hydra.

Suppose you want to benchmark PostgreSQL and MySQL for your application. When running of the application, you will need either MySQL or PostgreSQL - but not both.

The way to do this with Hydra is with a Config group. A config group is a mutually exclusive set of configuration files.

To create a config group, create a directory - db - that will hold a file for each database configuration alternative. Since we are expecting to have multiple config groups, we will proactively move all the configuration files into a conf directory.

Python file:

@hydra.main(config_path="conf")def my_app(cfg):    print(OmegaConf.to_yaml(cfg))

config_path can specify your config file as in the previous command line example, or the root directory for your configuration files. If a config file is specified, its directory is the root directory.

The directory structure of our application now looks like:

โ”œโ”€โ”€ confโ”‚ย ย  โ””โ”€โ”€ dbโ”‚ย ย      โ”œโ”€โ”€ mysql.yamlโ”‚ย ย      โ””โ”€โ”€ postgresql.yamlโ””โ”€โ”€

If you run it, it prints an empty config because no configuration was specified.

$ python{}

You can now choose which database configuration to use from the command line:

$ python db=postgresqldb:  driver: postgresql  pass: drowssap  timeout: 10  user: postgres_user

Like before, you can still override individual values in the resulting config:

$ python db=postgresql db.timeout=20db:  driver: postgresql  pass: drowssap  timeout: 20  user: postgres_user

This simple example demonstrated a very powerful feature of Hydra: You can compose your configuration object from multiple configuration files.