A simple way to manage your project settings.
It is inspired by Django's settings system but is generic for any python project.
With simple-settings you just need specify your settings module in --settings
arg of command line (or settings
of environment) and all settings will be available in simple_settings.settings
.
from simple_settings import settings
print settings.FOO
simple-settings is available on Pypi.
$ pip install simple-settings
simple-settings reads and stores all variables (or constants if you prefer) of a python module that you specify. For store your settings you need at least one python module. The objects in this python module, work as a mapping to settings of project, because, for each object in this module, simple-settings will seek it's value in environment before assuming the value presenting in module.
To specify your settings module you have two approaches, with command line or environment.
For example, imagine that you have a python module for your project settings and this file is in "settings/development.py" (a common example).
To load settings of this file you can run your project with command line arg --settings
:
$ python app.py --settings=settings.development
Or set the environment variable settings
:
$ export settings=settings.development
$ python app.py
The simple_settings.settings
object reads the command line and environment in this order (but simple-settings takes first value it encounters), to know which file to load.
This is a very dummy example, in real world you would use simple-settings in more complex cases.
In this example we just store a simple string but any python type is accepted.
SIMPLE_CONF = 'simple'
You don't need specify which setting simple-settings must load, you can do this with command line or environment.
from simple_settings import settings
print settings.SIMPLE_CONF
You can specify your settings module with command line:
$ python app.py --settings=project_settings
simple
Or environment:
$ export settings=project_settings
$ python app.py
simple
You can override the values of your settings module with environment variables.
$ export SIMPLE_CONF="simple from env"
$ python app.py --settings=project_settings
simple from env
Check examples, in project repository for more usage samples.
- First release.