Skip to main content

Override arbitrary Django settings via environment variables.

  • Free software: BSD license

Installation

pip install django-env-overrides

Documentation

django-env-overrides lets you quickly adjust an existing Django app to load arbitrary settings from environment variables.

Setup

Add these lines to the end of your setup.py file:

import django_env_overrides
django_env_overrides.apply_to(globals())

Any environment variable prefixed with DJANGO__ will now be imported to your settings.

Example

settings.py:

DEBUG = True
MEDIA_URL = '/media/'
DATABASES = {
    'default': {
        'ENGINE': 'sqlite3',
    }
}
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'OPTIONS': {
            'context_processors': [
                'django.contrib.auth.context_processors.auth',
            ]
        }
    }
]

import django_env_overrides
django_env_overrides.apply_to(globals())

Environment:

DJANGO__SECRET_KEY=secret
DJANGO__MEDIA_URL=/new_url/
DJANGO__bool__DEBUG=False
POSTGRES=postgres://uf07k1:wegauwhg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722
DJANGO__db__DATABASES__default=$POSTGRES
DJANGO__TEMPLATES__0__OPTIONS__context_processors__1='my.context.processor'

Result:

DEBUG = False
MEDIA_URL = '/new_url/'
SECRET_KEY = 'secret'
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'd8r82722',
        'HOST': 'ec2-107-21-253-135.compute-1.amazonaws.com',
        'USER': 'uf07k1',
        'PASSWORD': 'wegauwhg',
        'PORT': 5431,
    }
}
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'OPTIONS': {
            'context_processors': [
                'django.contrib.auth.context_processors.auth',
                'my.context.processor',
            ]
        }
    }
]

Format for environment variables

The general format for environment variable names is:

<prefix>__<typecast>__<path>__<to>__<target>__<setting>

<prefix> defaults to DJANGO. If you want to use another prefix, use django_env_overrides.apply_to(globals(), prefix="MYPREFIX").

<typecast> (optional) is any type known to the django-environ package.

Currently the supported types are str, bool, int, float, json, list, tuple, dict, url, path, db_url, cache_url, search_url, and email_url. See the django-environ package for usage.

<typecast> is optional and defaults to str.

<path>__<to>__<target>__<setting> specifies the setting or subsetting the value should be assigned to. Path elements are treated as array indexes if they are integers, and otherwise as dictionary keys.

Development

See CONTRIBUTING.rst

Changelog

0.1.0 (2016-07-21)

  • First release on PyPI.

Metadata

Release files for django-env-overrides 0.1.0

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

Source distribution (sdist)

Source distribution for django-env-overrides 0.1.0
File Size Uploaded Provenance
django-env-overrides-0.1.0.tar.gz 10.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-env-overrides 0.1.0
File Interpreter ABI Platform
django_env_overrides-0.1.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 15.7 kB

Release files / django-env-overrides-0.1.0.tar.gz

Download URL django-env-overrides-0.1.0.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
2f7c1311a3e0fc5f3dbcfc4e25f3a0b4518f2e9ac37dc49a3a098973e7f1124e
BLAKE2b-256 checksum
How to use checksums
2ca7d03111753170ca0707c00859240f56bde8f8a999a82ecdf17b2265ec4203
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_env_overrides-0.1.0-py2.py3-none-any.whl

Download URL django_env_overrides-0.1.0-py2.py3-none-any.whl
Size 5.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
3eb1f4718160cc7b1b8c1997c7442442048d2c3deb8aa3bebd4008a7c5e87aa0
BLAKE2b-256 checksum
How to use checksums
c15fbc7f7ac4f896c157055c6ac6a3b5a45ace65aa48990a37763be3f3beb736
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-env-overrides 0.1.0

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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