Skip to main content
Version: 1.1

Grouping config files

ย Example

Suppose you want to benchmark your application on each of PostgreSQL and MySQL. To do this, use config groups.

A Config Group is a named group with a set of valid options. Selecting a non-existent config option generates an error message with the valid options.

Creating config groups#

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

Directory layout
โ”œโ”€ conf
โ”‚ โ””โ”€ db
โ”‚ โ”œโ”€ mysql.yaml
โ”‚ โ””โ”€ postgresql.yaml
driver: mysql
user: omry
password: secret
driver: postgresql
user: postgres_user
password: drowssap
timeout: 10

Using config groups#

Since we moved all the configs into the conf directory, we need to tell Hydra where to find them using the config_path parameter. config_path is a directory relative to
def my_app(cfg: DictConfig) -> None:

Running without requesting a configuration will print an empty config.

$ python

Select an item from a config group with +GROUP=OPTION, e.g:

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

By default, the config group determines where the config content is placed inside the final config object. In Hydra, the path to the config content is referred to as the config package. The package of db/postgresql.yaml is db:

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

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

Advanced topics#

Last updated on by Jasha10