12-factor.net settings support for Django based on envex
Project description
django-settings-env
12-factor.net settings environment handler for Django
envex
The functionality outlined in this section is derived from the dependent package
envex
, the docs for which are partially repeated below.
Skip to the Django Support section for functionality added by this extension.
envex
provides a convenient type-smart interface for handling the environment, and therefore
configuration of any application using 12factor.net principals removing many environment specific
variables and security sensitive information from application code.
This module provides some features not supported by other dotenv handlers (python-dotenv, etc.) including expansion of template variables which is very useful for DRY.
More detailed info can be found in the envex
README.
Django Support
By default, the Env class provided by this module can apply a given prefix (default "DJANGO_")
to environment variables names, but will only be used in that form if the raw (unprefixed)
variable name is not set in the environment. To change the prefix including setting it to
an empty string, pass the prefix= kwarg to Env.__init__
.
Some django specific methods included in this module are URL parsers for:
Default Var | Parser |
---|---|
DATABASE_URL | env.database_url() |
CACHE_URL | env.cache_url() |
EMAIL_URL | env.email_url() |
SEARCH_URL | env.search_url() |
QUEUE_URL | env.queue_url() |
each of which can be injected into django settings via the environment, typically from a .env file at the project root.
The name of the file and paths searched is fully customisable.
The url specified includes a schema that determines the "backend" class or module that handles the corresponding functionality as documented below.
database_url
Evaluates a URL in the form
schema://[username:[password]@]host_or_path[:port]/name
Schemas:
Scheme | Database |
---|---|
postgres | Postgres (psycopg2) |
postgresql | Postgres (psycopg2) |
psql | Postgres (psycopg2) |
pgsql | Postgres (psycopg2) |
postgis | Postgres (psycopg2) using PostGIS extensions |
mysql | MySql (mysqlclient) |
mysql2 | MySql (mysqlclient) |
mysql-connector | MySql (mysql-connector) |
mysqlgis | MySql (mysqlclient) using GIS extensions |
mssql | SqlServer (sql_server.pyodbc) |
oracle | Oracle (cx_Oracle) |
pyodbc | ODBC (pyodbc) |
redshift | Amazon Redshift |
spatialite | Sqlite with spatial extensions (spatialite) |
sqlite | Sqlite |
ldap | django-ldap |
cache_url
Evaluates a URL in the form
schema://[username:[password]@]host_or_path[:port]/[name]
Schemas:
Scheme | Cache |
---|---|
dbcache | cache in database |
dummycache | dummy cache - "no cache" |
filecache | cache data in files |
locmemcache | cache in memory |
memcache | memcached (python-memcached) |
pymemcache | memcached (pymemcache) |
rediscache | redis (django-redis) |
redis | redis (django-redis) |
email_url
Evaluates a URL in the form
schema://[username[@domain]:[password]@]host_or_path[:port]/
Schemas:
Scheme | Service |
---|---|
smtp | smtp, no SSL |
smtps | smtp over SSL |
smtp+tls | smtp over SSL |
smtp+ssl | smtp over SSL |
consolemail | publish mail to console (dev) |
filemail | append email to file (dev) |
memorymail | store emails in memory |
dummymail | do-nothing email backend |
amazonses | Amazon Wimple Email Service |
amazon-ses | Amazon Wimple Email Service |
search_url
Evaluates a URL in the form
schema://[username:[password]@]host_or_path[:port]/[index]
Schemas:
Scheme | Engine |
---|---|
elasticsearch | elasticsearch (django-haystack) |
elasticsearch2 | elasticsearch2 (django-haystack) |
solr | Apache solr (django-haystack) |
whoosh | Whoosh search engine (pure python, haystack) |
xapian | Xapian search engine (haystack) |
simple | Simple search engine (haystack) |
queue_url
Evaluates a URL in the form
schema://[username:[password]@]host_or_path[:port]/[queue]
Schemas:
Scheme | Engine |
---|---|
rabbitmq | RabbitMQ |
redis | Redis |
amazonsqs | Amazon SQS |
amazon-sqs | alias for Amazon SQS |
Django Class Settings
Support for the django-class-settings
module is added to the env handler, allowing
a much simplified use withing a class_settings.Settings class, e.g.:
from django_settings_env import Env
from class_settings import Settings
env = Env(prefix='DJANGO_')
class MySettings(Settings):
MYSETTING = env()
This usage will look for 'MYSETTING' or 'DJANGO_MYSETTNG' in the environment and lazily assign it to the MYSETTING value for the settings class.
:warning: The functional form of env() is now available even if django class settings is not used or installed.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-settings-env-4.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ccc4896a151bc9ce83a509301ea83469641ccb8ed69c30e058486a8da254ce4 |
|
MD5 | fb642c3bb1d0eba2a590609e6e37ad2d |
|
BLAKE2b-256 | 17e43e2f2c447f73815fb6756b7da3dfc8e4afd9e960ebdaa690a8ed293bf5c4 |
Hashes for django_settings_env-4.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb544ead76080a66dc8fdf57aad44bbe1b514ae42da1ad108fb207e79272c6e0 |
|
MD5 | 5f1924d04f3bf325ecc324125a70b6cb |
|
BLAKE2b-256 | 541e2b666442774dd25297e5c2487b521eb13e7750d1202e1c1f3e7b1a5ebeac |