enviro lets you set default values of os.environ
from a configuration file. This can be useful if you want to be able to override parts of your configuration based on the running environment. Using this approach is ideal for when you want your configuration to play nicely with PaaS services.
from enviro import setdefault
setdefault('mysettings.conf')
enviro will now look in the following directories for a file called mysettings.conf
:
- Current Working Directory
cwd
- Home directory
$HOME
/etc
- The path of the executed script.
__file__
of__main__
import os
import enviro
enviro.setdefault('mysettings.conf')
os.environ['foodir']
# Will give you 'frob/whatever' based on the example config below.
If foodir
was already defined in the environment, enviro would not have overwritten it.
The configuration file is in normal .ini
format without section headers. It supports interpolation as you would expect.
foodir: %(dir)s/whatever
dir=frob
long: this value continues
in the next line
Install enviro with pip:
$ pip install enviro
GPL v.2