Version: Next

Introduction to Structured Configs

This is an advanced tutorial that assumes that you are comfortable with the concepts introduced in the Basic Tutorial. The examples in this tutorial are available here.

Structured Configs use Python dataclasses to describe your configuration structure and types. They enable:

  • Runtime type checking as you compose or mutate your config
  • Static type checking when using static type checkers (mypy, PyCharm, etc.)

Structured Configs supports:

  • Primitive types (int, bool, float, str, Enums)
  • Nesting of Structured Configs
  • Containers (List and Dict) containing primitives or Structured Configs
  • Optional fields

Structured Configs Limitations:

  • Union types are not supported (except Optional)
  • User methods are not supported

There are two primary patterns for using Structured configs

  • As a config, in place of configuration files (often a starting place)
  • As a config schema validating configuration files (better for complex use cases)

With both patterns, you still get everything Hydra has to offer (config composition, Command line overrides etc). This tutorial covers both. *Read it in order*.

Hydra supports OmegaConf's Structured Configs via the ConfigStore API. This tutorial does not assume any knowledge of them. It is recommended that you visit the OmegaConf Structured Configs page to learn more later.


Last updated on by Rosario Scalise