Skip to main content
Version: 1.1

Defaults List


You can define a defaults list in your primary Structured Config just like you can in your primary config.yaml file. The example below extends the previous example by adding a defaults list that will load db=mysql by default.

from omegaconf import MISSING, OmegaConf
class MySQLConfig:
class PostGreSQLConfig:
defaults = [
# Load the config "mysql" from the config group "db"
{"db": "mysql"}
class Config:
# this is unfortunately verbose due to @dataclass limitations
defaults: List[Any] = field(default_factory=lambda: defaults)
# Hydra will populate this field based on the defaults list
db: Any = MISSING
cs = ConfigStore.instance()"db", name="mysql", node=MySQLConfig)"db", name="postgresql", node=PostGreSQLConfig)"config", node=Config)
@hydra.main(config_path=None, config_name="config")
def my_app(cfg: Config) -> None:
if __name__ == "__main__":

Running loads the mysql config option by default:

$ python
driver: mysql

You can override the default option via the command line:

$ python db=postgresql
driver: postgresql

Requiring users to specify a default list value#

Set db as MISSING to require the user to specify a value on the command line.

Defaults list with a missing db
defaults = [
{"db": MISSING}
$ python
You must specify 'db', e.g, db=<OPTION>
Available options:
Last updated on by Jasha10