Skip to main content
Version: 1.0

Static schema with many configs

ย Example

We have seen that if the name of the config file matches the name of a configs stored in the ConfigStore it will be used to validate the config file automatically. This is useful if there is a one-to-one mapping between the Structured Configs and the YAML files. Such convenient mapping does not exist when we have many config files and just one schema.

If the config has a static structure, You can define it using Structured Configs. Any config merged into this config structure will be validated against the schema you define.

class DBConfig:
driver: str = MISSING
host: str = MISSING
user: str = MISSING
password: str = MISSING
class Config:
db: DBConfig = MISSING
cs = ConfigStore.instance()"config", node=Config)
def my_app(cfg: Config) -> None:
if __name__ == "__main__":
Config directory
โ”œโ”€โ”€ config.yaml
โ””โ”€โ”€ db
โ”œโ”€โ”€ prod.yaml
โ”œโ”€โ”€ qa.yaml
โ””โ”€โ”€ staging.yaml
- db: staging
# @package _group_
driver: mysql
host: mysql001.staging
user: root
password: root

In the above example, the 3 yaml files has the structure compatible with the Config dataclass. You can have as many such configs as you want.

$ python db=prod
driver: mysql
user: root
password: '1234'
Last updated on by Jasha10