Skip to main content

django-12factor

https://travis-ci.org/doismellburning/django12factor.svg?branch=master Code Health Requirements Status Coverage Status

What is it?

Django is an awesome Python web framework.

“The Twelve-Factor App“ is an awesome methodology for building SaaS apps.

django-12factor makes Django more 12factor-y. Right now, this focuses on the Config - “Store config in the environment”; Heroku users with addons will be particularly familiar with this.

Still not sure of the benefits? Check out “Twelve-Factor Config: Misunderstandings and Advice”.

Usage

Add the following to the bottom of your settings.py:

import django12factor
d12f = django12factor.factorise()

factorise() returns a dict of settings, so you can now use and assign them as you wish, e.g.

DEBUG = d12f['DEBUG']
LOGGING = d12f['LOGGING']

If you don’t like that repetition, you can (ab)use globals() like so:

import django12factor
d12f = django12factor.factorise()

def f(setting):
    globals()[setting] = d12f[setting]

f('DEBUG')
f('LOGGING')

You can also add non-Django settings this way, e.g. keys to APIs:

custom_settings = (
    "GOOGLE_ANALYTICS_KEY",
    "MAILCHIMP_API_KEY",
)
d12f = django12factor.factorise(custom_settings=custom_settings)

MAILCHIMP_API_KEY = d12f['MAILCHIMP_API_KEY']
GOOGLE_ANALYTICS_KEY = d12f['GOOGLE_ANALYTICS_KEY']

In the event of a custom_setting not being set in the environment, it will default to None.

Give me everything!

If you say so…

import django12factor
globals().update(django12factor.factorise())

Utilities

django12factor.getenv_bool is a utility function that takes the name of an environment variable, and returns True _unless_ it is set to either a “falsey” string (e.g. "no") or not set.

Settings

The following settings are currently supported:

DEBUG

Defaults to False for safety reasons, otherwise True unless os.environ("DEBUG") is a “falsy” string.

TEMPLATE_DEBUG

As for DEBUG, but defaults to the value of DEBUG.

CACHES

Uses django-cache-url to parse os.environ("CACHE_URL").

LOGGING

A static LOGGING dict that configures 12factor-style logging.

DATABASES

Uses dj-database-url - parses DATABASE_URL if it exists, otherwise falls back to in-memory sqlite.

Anything of the form FOO_DATABASE_URL will be parsed as DATABASES['foo'], allowing you to configure multiple databases via the environment.

ALLOWED_HOSTS

Treats os.environ("ALLOWED_HOSTS") as a comma-separated list.

SECRET_KEY

Uses os.environ("SECRET_KEY") - required if DEBUG==False.

Metadata

Release files for django12factor 1.3

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

Source distribution (sdist)

Source distribution for django12factor 1.3
File Size Uploaded Provenance
django12factor-1.3.tar.gz 4.6 kB Without provenance Details

Release files / django12factor-1.3.tar.gz

Download URL django12factor-1.3.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
3e20e4b0174a34af6f22106f1da29fab98cc0c9852e18437a3eda56883622164
BLAKE2b-256 checksum
How to use checksums
0fdf8ed56ceb9885c37390034cdfefabb595f2cc17e832d55f0926753fa11150
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django12factor 1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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