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: 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
from omegaconf import DictConfig, OmegaConf
import hydra

@hydra.main(version_base=None, config_path="conf")
def my_app(cfg: DictConfig) -> None:

if __name__ == "__main__":

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​