Twelve is a utility for using 12factor inspired settings in Python. It provides
a Configuration
class which abstracts away pulling settings out of the environment
and normalizing them and small adapters to make it easy to use those values
in various popular frameworks.
There have been a few projects doing similar things, such as dj-database-url, dj-cache-url, and django-heroku-memcacheify. Each one of them handling the backing service configuration for a single archetype of service (database, cache, etc) and tied to a specific framework (and in one case, to a specific framework on a specific hosting platform).
Twelve attempts to provide a uniform and simple API to using 12factor inspired configuration without being tied to a specific archetype of backing service, nor to a single framework or hosting provider.
# Setup Environment (Normally Done Externally to Configuration) import os os.environ["DATABASE_URL"] = "postgres://user:pass@hostname:5432/dbname" # Load Twelve Configuration import twelve config = twelve.Configuration() # Use Values import psycopg2 conn = psycopg2.connect( host=config.databases["default"]["host"], port=config.databases["default"]["port"], user=config.databases["default"]["user"], password=config.databases["default"]["password"], database=config.databases["default"]["name"], )
# Setup Environment (Normally Done Externally to Configuration) import os os.environ["DATABASE_URL"] = "postgres://user:pass@hostname:5432/dbname" # Load Twelve Environment import twelve config = twelve.Configuration(adapter="django") DATABASES = config.databases