Package: django-settings-env
django-settings-env12-factor.net settings environment handler for Django settings.envexThe primary functionality of this module is provided by the dependencyenvex,
which provides settings via the OS environment,.envfiles and, optionally,
HashiCorp vault (sinceenvexv2.0).envexprovides 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.
Settings may be set in .env files, directly within the environment, or in HashiCorp vault.By default, values set in the environment take priority over those set in .env files, and
those take priority of any corresponding values stored in Vault.
This can be changed by setting$ENVEX_SOURCEor any value other thanenv.Some features not supported by other dotenv handlers (python-dotenv, etc.) are available
including expansion of template variables, which is very useful for DRY.Django SettingsBy default, the Django Env class can apply a given prefix (default is "DJANGO_")
to environment variables names, but will only be used in that form if the raw (no prefix)
variable name is not already set in the environment.
To change the prefix including setting it to an empty string, pass the prefix= kwarg toEnv().One key difference betweenenvexanddjango-settings-envis that the latter will read .env files
by default, and will automatically search parent directories if one is not found where initially expected.
This behaviour needs to be explicitly enabled inenvex.Some django specific methods included in this module are URL parsers for:Default VarParserDATABASE_URLenv.database_url()CACHE_URLenv.cache_url()EMAIL_URLenv.email_url()SEARCH_URLenv.search_url()QUEUE_URLenv.queue_url()each of which can be injected into django settings via the environment, typically
from a .env file at the project root, or set from a variable in vault.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_urlEvaluate a URL in the formschema://[username:[password]@]host_or_path[:port]/nameSchemas:SchemeDatabasepostgresPostgres (psycopg2 or psycopg)postgresqlPostgres (psycopg2 or psycopg)psqlPostgres (psycopg2 or psycopg)pgsqlPostgres (psycopg2 or psycopg)postgisPostgres (psycopg2 or psycopg) + PostGISmysqlMySql (mysqlclient)mysql2MySql (mysqlclient)mysql-connectorMySql (mysql-connector)mysqlgisMySql (mysqlclient) using GIS extensionsmssqlSqlServer (sql_server.pyodbc)oracleOracle (cx_Oracle)pyodbcODBC (pyodbc)redshiftAmazon RedshiftspatialiteSqlite with spatial extensions (spatialite)sqliteSqliteldapdjango-ldapcache_urlEvaluate a URL in the formschema://[username:[password]@]host_or_path[:port]/[name]Schemas:SchemeCachedbcachecache in databasedummycachedummy cache - "no cache"filecachecache data in fileslocmemcachecache in memorymemcachememcached (python-memcached)pymemcachememcached (pymemcache)rediscacheredis (django-redis)redisredis (django-redis)email_urlEvaluate a URL in the formschema://[username[@domain]:[password]@]host_or_path[:port]/Schemas:SchemeServicesmtpsmtp, no SSLsmtpssmtp over SSLsmtp+tlssmtp over SSLsmtp+sslsmtp over SSLconsolemailpublish mail to console (dev)filemailappend email to file (dev)memorymailstore emails in memorydummymaildo-nothing email backendamazonsesAmazon Wimple Email Serviceamazon-sesAmazon Wimple Email Servicesearch_urlEvaluate a URL in the formschema://[username:[password]@]host_or_path[:port]/[index]Schemas:SchemeEngineelasticsearchelasticsearch (django-haystack)elasticsearch2elasticsearch2 (django-haystack)solrApache solr (django-haystack)whooshWhoosh search engine (pure python, haystack)xapianXapian search engine (haystack)simpleSimple search engine (haystack)queue_urlEvaluate a URL in the formschema://[username:[password]@]host_or_path[:port]/[queue]Schemas:SchemeEnginerabbitmqRabbitMQredisRedisamazonsqsAmazon SQSamazon-sqsalias for Amazon SQSDjango Class SettingsSupport for thedjango-class-settingsmodule is added to the env handler, allowing a much simplified use withing a class_settings.Settings class, e.g.:fromdjango_settings_envimportEnv# noinspection PyUnresolvedReferencesfromclass_settingsimportSettingsenv=Env(prefix='DJANGO_')classMySettings(Settings):MYSETTING=env()This usage will look for 'MYSETTING' or 'DJANGO_MYSETTING' 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 ifdjango-class-settingsis not
used or installed and is available at the settings module level.Vault SupportSee theenvexdocumentation for details on how to configure this package with HashiCorp Vault.