File size: 5,040 Bytes
fc0f7bd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | ---
id: intro
title: Getting started
sidebar_label: Getting started
---
## Introduction
Hydra is an open-source Python framework that simplifies the development of research and other complex applications.
The key feature is the ability to dynamically create a hierarchical configuration by composition and override it through config files and the command line.
The name Hydra comes from its ability to run multiple similar jobs - much like a Hydra with multiple heads.
### Key features:
* Hierarchical configuration composable from multiple sources
* Configuration can be specified or overridden from the command line
* Dynamic command line tab completion
* Run your application locally or launch it to run remotely
* Run multiple jobs with different arguments with a single command
## Versions
Hydra supports Linux, Mac and Windows.
| | Version | Docs | Release notes | Python Version |
| -------|---------------------------|------------------------------- | ------------------------------------------------------------------------------------- | ----------------- |
| ►| 0.11 (Stable) | 0.11 Docs | [Release notes](https://github.com/facebookresearch/hydra/releases/tag/0.11.0) | **2.7, 3.5+** |
| | 1.0 (Release candidate) | [1.0 docs](../docs/next/intro)| [Release notes](https://github.com/facebookresearch/hydra/releases/tag/hydra-1.0.0rc1) | 3.6+ |
## Quick start guide
This guide will show you some of the most important features of Hydra.
Read the [tutorial](tutorial/1_simple_cli_app.md) to gain a deeper understanding.
### Installation
Install Hydra 0.11 with `pip install hydra-core --upgrade`.
### Basic example
Configuration file: `config.yaml`
```yaml
db:
driver: mysql
user: omry
pass: secret
```
Python file: `my_app.py`
```python {4-6}
import hydra
from omegaconf import DictConfig
@hydra.main(config_path="config.yaml")
def my_app(cfg : DictConfig) -> None:
print(cfg.pretty())
if __name__ == "__main__":
my_app()
```
You can learn more about OmegaConf [here](https://omegaconf.readthedocs.io/en/latest/usage.html#access-and-manipulation) later.
`config.yaml` is loaded automatically when you run your application
```yaml
$ python my_app.py
db:
driver: mysql
pass: secret
user: omry
```
You can override values in the loaded config from the command line:
```yaml {4-5}
$ python my_app.py db.user=root db.pass=1234
db:
driver: mysql
user: root
pass: 1234
```
### Composition example
You may want to alternate between two different databases. to support this create a `config group` named db,
and place one config file for each alternative inside:
The directory structure of our application now looks like:
```text
βββ db
β βββ mysql.yaml
β βββ postgresql.yaml
βββ config.yaml
βββ my_app.py
```
Here is the new `config.yaml`
```yaml
defaults:
- db: mysql
# some other config options in your config file.
website:
domain: example.com
```
`defaults` is a special directive telling Hydra to use db/mysql.yaml when composing the configuration object.
The resulting cfg object is a composition of configs from defaults with configs specified in your `config.yaml`.
You can now choose which database configuration to use from the and override values from the command line:
```yaml
$ python my_app.py db=postgresql db.timeout=20
db:
driver: postgresql
pass: drowssap
timeout: 20
user: postgre_user
website:
domain: example.com
```
You can have as many config groups as you need.
### Multirun
You can run your function multiple times with different configuration easily with the `--multirun|-m` flag.
```
$ python my_app.py --multirun db=mysql,postgresql
[HYDRA] Sweep output dir : multirun/2020-01-09/01-16-29
[HYDRA] Launching 2 jobs locally
[HYDRA] #0 : db=mysql
db:
driver: mysql
pass: secret
user: omry
website:
domain: example.com
[HYDRA] #1 : db=postgresql
db:
driver: postgresql
pass: drowssap
timeout: 10
user: postgre_user
website:
domain: example.com
```
There is a whole lot more to Hydra. Read the [tutorial](tutorial/1_simple_cli_app.md) to learn more.
## Other stuff
### Community
Ask questions in the chat or StackOverflow (Use the tag #fb-hydra):
* [Zulip Chat](https://hydra-framework.zulipchat.com)
* [StackOverflow](https://stackoverflow.com/questions/tagged/fb-hydra)
Follow Hydra on Twitter and Facebook:
* [Facebook page](https://www.facebook.com/Hydra-Framework-109364473802509/)
* [Twitter](https://twitter.com/Hydra_Framework)
### Citing Hydra
If you use Hydra in your research please use the following BibTeX entry:
```text
@Misc{,
author = {Omry Yadan},
title = {A framework for elegantly configuring complex applications},
howpublished = {Github},
year = {2019},
url = {https://github.com/facebookresearch/hydra}
}
```
|