Skip to content
Override Python dict contents with YAML file and/or environment variables
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
tests
.gitignore
.travis.yml
CHANGELOG.md
LICENSE.mit
README.md
settings_overrider.py
setup.cfg
setup.py

README.md

settings-overrider

Build Status

Override Python dict contents with YAML file and/or environment variables.

Originally created for Django settings but may be useful in other cases.

Install

pip install settings-overrider

Use

# settings.py

from settings_overrider import override

...

# at the end of the file
override(globals(), ...)

Use YAML file path:

override(globals(), yaml='/etc/project-settings.yaml')

Use YAML file:

with open('/etc/project-settings.yaml') as f:
    override(globals(), yaml=f)

Use all environment variables with specified prefix:

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

git clone https://github.com/kottenator/settings-overrider.git
cd settings-overrider
pip install -e '.[test]'
py.test
You can’t perform that action at this time.