Skip to main content

bienvenue

PyPI Build Status Coverage Report

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:

pip install bienvenue

Usage

Bienvenue provides the function make_env_reader which returns a new function for accessing the environment. For example:

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.

Release files for bienvenue 3.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bienvenue 3.0.1
File Size Uploaded
bienvenue-3.0.1.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bienvenue 3.0.1
File Interpreter ABI Platform
bienvenue-3.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.7 kB

Release files / bienvenue-3.0.1.tar.gz

Download URL bienvenue-3.0.1.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
9cafe50a37e9df8b4f31fcecccc9c36a7e939f7523da6cd860205d6b2afd4962
BLAKE2b-256 checksum
How to use checksums
79283ac12e1d5632c4f6f5523b4f6789eed93ed588591b98287f479b0dae8ca2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.9.1 pkginfo/1.3.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.19.6 CPython/3.6.6

Release files / bienvenue-3.0.1-py3-none-any.whl

Download URL bienvenue-3.0.1-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e1b2232d64016414e67203855a805d30e7db969d3d72b7eb4f6b320174c14b2e
BLAKE2b-256 checksum
How to use checksums
b40cf9164f6430f6b12437205c02679bf065bdb069e0d64480ed452216c41e53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.9.1 pkginfo/1.3.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.19.6 CPython/3.6.6

Release history Release notifications | RSS feed

This release

3.0.1 This release

2 release files

3.0.0

1 release file

2.0.0

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page