Skip to main content
Version: Next

Grouping config files

ย Example (Click Here)

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: mysqluser: omrypassword: secret

driver: postgresqluser: postgres_userpassword: drowssaptimeout: 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
@hydra.main(config_path="conf")def my_app(cfg: DictConfig) -> None:    print(OmegaConf.to_yaml(cfg))

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=postgresqldb:  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=20db:  driver: postgresql  pass: drowssap  timeout: 20  user: postgres_user

Advanced topics#