https://github.com/kottenator/settings-overrider
Override Python dict contents with YAML file and/or environment variables
https://github.com/kottenator/settings-overrider
Last synced: about 1 year ago
JSON representation
Override Python dict contents with YAML file and/or environment variables
- Host: GitHub
- URL: https://github.com/kottenator/settings-overrider
- Owner: kottenator
- License: mit
- Created: 2016-01-02T05:05:59.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2021-06-21T06:33:39.000Z (almost 5 years ago)
- Last Synced: 2025-04-13T22:17:45.760Z (about 1 year ago)
- Language: Python
- Size: 8.79 KB
- Stars: 7
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.mit
Awesome Lists containing this project
README
# settings-overrider
[](https://travis-ci.org/kottenator/settings-overrider)
Override Python dict contents with YAML file and/or environment variables.
Originally created for Django settings but may be useful in other cases.
## Install
```sh
pip install settings-overrider
```
## Use
```py
# settings.py
from settings_overrider import override
...
# at the end of the file
override(globals(), ...)
```
Use YAML file path:
```py
override(globals(), yaml='/etc/project-settings.yaml')
```
Use YAML file:
```py
with open('/etc/project-settings.yaml') as f:
override(globals(), yaml=f)
```
Use all environment variables with specified prefix:
```py
override(globals(), env='PRJ_')
```
Prefix will be omitted, i.e. `PRJ_DEBUG` variable will become `DEBUG` setting.
Variable content will be parsed as YAML so you can use:
- `True` / `False`: bool
- `Text` / `"Text"`: string
- `123`: number
- `{ default: { ENGINE: django.db.backends.sqlite3, NAME: /tmp/prj.sqlite3 }}` -
nested dicts
You can combine YAML file and environment variables.
## Contribute and test
```sh
git clone https://github.com/kottenator/settings-overrider.git
cd settings-overrider
pip install -e '.[test]'
py.test
```