Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/scampersand/bienvenue
Python module for reading config from environment for 12 factor apps
https://github.com/scampersand/bienvenue
Last synced: 25 days ago
JSON representation
Python module for reading config from environment for 12 factor apps
- Host: GitHub
- URL: https://github.com/scampersand/bienvenue
- Owner: scampersand
- License: mit
- Created: 2017-01-28T23:04:13.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-09-24T16:40:27.000Z (over 6 years ago)
- Last Synced: 2024-11-07T05:42:25.492Z (3 months ago)
- Language: Python
- Size: 29.3 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
=========
bienvenue
=========|PyPI| |Build Status| |Coverage Report| |Python Versions|
Python module for reading config from environment for `12-factor apps `_.
Supports Python 3.4+Rationale
---------In a 12-factor app, `config comes from the environment `_.
For example, on Heroku, config variables are set using ``heroku config:set`` on the command line,
then `passed to the application in the environment `_.Reading and parsing config from the environment is tedious and error-prone. For
example, a Django app has ``settings.DEBUG`` which should be
either ``True`` or ``False``. The operator runs ``heroku config:set DJANGO_DEBUG
off`` intending to disable it, but the application only sees a non-empty string
and treats the value as ``True``.This sort of problem can be handled case-by-case but doesn't need to be. Clearly
a configuration setting with a fallback boolean value should be interpreted as
boolean from the environment. Likewise a fallback integer setting indicates the
associated environment variable should be converted from string to int.Sounds like a job for a small and well-tested Python module, right?
Installation
------------Install from PyPI_:
.. code:: sh
pip install bienvenue
Usage
-----Bienvenue provides the function ``make_env_reader`` which returns a new
function for accessing the environment. For example:.. code:: python
from bienvenue import make_env_reader
env = make_env_reader(prefix='MY_')
DEBUG = env('DEBUG', False)
SECRET_KEY = env('SECRET_KEY', 'fallback-secret-for-dev')
ALLOWED_HOSTS = env('ALLOWED_HOSTS', [])The env reader looks for ``MY_DEBUG`` in ``os.environ``. If it's not there,
the default value ``False`` will be returned. However if it's found, then the
value there will be interpreted according to the type of the default, in this
case boolean. Common strings such as on/off, true/false and yes/no are
interpreted into ``True`` or ``False``.Likewise ``SECRET_KEY`` will be extracted from ``MY_SECRET_KEY`` and then
interpreted as a string value.``ALLOWED_HOSTS`` will be extracted from ``MY_ALLOWED_HOSTS`` and JSON
decoded as a list, since the default value is a list.If bienvenue encounters unknown types or values during parsing, it will log an
error and fall back to the provided default.Legal
-----Copyright 2017-2018 `Scampersand LLC `_
Released under the `MIT license `_
.. _PyPI: https://pypi.python.org/pypi/bienvenue
.. |Build Status| image:: https://img.shields.io/travis/scampersand/bienvenue/master.svg?style=plastic
:target: https://travis-ci.org/scampersand/bienvenue?branch=master.. |Coverage Report| image:: https://img.shields.io/codecov/c/github/scampersand/bienvenue/master.svg?style=plastic
:target: https://codecov.io/gh/scampersand/bienvenue/branch/master.. |PyPI| image:: https://img.shields.io/pypi/v/bienvenue.svg?style=plastic
:target: PyPI_.. |Python Versions| image:: https://img.shields.io/pypi/pyversions/bienvenue.svg?style=plastic
:target: PyPI_