Skip to main content
Version: 1.1

A simple command-line application

 Example

This is a simple Hydra application that prints your configuration. The my_app function is a place holder for your code. We will slowly evolve this example to showcase more Hydra features.

The examples in this tutorial are available here.

my_app.py
from omegaconf import DictConfig, OmegaConfimport hydra
@hydra.main(config_path=None)def my_app(cfg: DictConfig) -> None:    print(OmegaConf.to_yaml(cfg))
if __name__ == "__main__":    my_app()

In this example, Hydra creates an empty cfg object and pass it to the function annotated with @hydra.main.

You can add config values via the command line. The + indicates that the field is new.

$ python my_app.py +db.driver=mysql +db.user=omry +db.password=secretdb:  driver: mysql  user: omry  password: secret
info

We will learn more about the config_path in the following pages.

See Hydra's command line flags and Basic Override Syntax for more information about the command line.