Skip to content

Commit

Permalink
Add instruction for config through environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
okomestudio committed Apr 12, 2020
1 parent 856e4c6 commit 863b94b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ can:
- Read from multiple configuration file formats: INI, JSON, TOML, and
YAML.

- Read from environment variables: Configuration can be easily
overridden with environment variables.

- Dynamically reload configuration at run time: Watch functions can be
attached to any keys within the configuration, so that separate
resources can be reloaded and managed.
Expand Down Expand Up @@ -46,6 +49,24 @@ config = ResConfig({"pg": {"dbname": "foo"}}) # with default config
config = ResConfig({"pg.dbname": "foo"}}) # this also works
```

For the configuration items that exist by default, environment
variables can override their values. Say your application, *myapp.py*
defines the following configuration by default.

``` bash
config = ResConfig({"pg.dbname": "foo"}})
```

When you run this app, you can use the `PG__DBNAME` environment
variable to override the default config:

``` bash
$ PG__DBNAME=bar python myapp.py # config.get('pg.dbname') will be `bar`
```

Note that for nested keys, a double underscore (`__`) delimits them,
and all keys are upper-cased by convention, as in this example.


### Watching for Configuration Changes

Expand Down

0 comments on commit 863b94b

Please sign in to comment.