Package: django-environ-plus
django-environis the Python package that allows you to useTwelve-factor methodologyto configure your
Django application with environment variables.For that, it gives you an easy way to configure Django application using
environment variables obtained from an environment file and provided by the OS:importenvironimportosenv=environ.Env(# set casting, default valueDEBUG=(bool,False))# Set the project base directoryBASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))# Take environment variables from .env fileenviron.Env.read_env(os.path.join(BASE_DIR,'.env'))# False if not in os.environ because of casting aboveDEBUG=env('DEBUG')# Raises Django's ImproperlyConfigured# exception if SECRET_KEY not in os.environSECRET_KEY=env('SECRET_KEY')# Parse database connection url strings# like psql://user:pass@127.0.0.1:8458/dbDATABASES={# read os.environ['DATABASE_URL'] and raises# ImproperlyConfigured exception if not found## The db() method is an alias for db_url().'default':env.db(),# read os.environ['SQLITE_URL']'extra':env.db_url('SQLITE_URL',default='sqlite:////tmp/my-tmp-sqlite.db')}CACHES={# Read os.environ['CACHE_URL'] and raises# ImproperlyConfigured exception if not found.## The cache() method is an alias for cache_url().'default':env.cache(),# read os.environ['REDIS_URL']'redis':env.cache_url('REDIS_URL')}The idea of this package is to unify a lot of packages that make the same stuff:
Take a string fromos.environ, parse and cast it to some of useful python
typed variables. To do that and to use the12factorapproach, some connection strings are expressed as url, so this package can parse
it and return aurllib.parse.ParseResult. These strings fromos.environare loaded from a.envfile and filled inos.environwithsetdefaultmethod, to avoid to overwrite the real environ.
A similar approach is used inTwo Scoops of Djangobook and explained in12factor-djangoarticle.Usingdjango-environyou can stop to make a lot of unversionedsettings_*.pyto configure your app.
Seecookiecutter-djangofor a concrete example on using with a django project.Feature SupportFast and easy multi environment for deployFillos.environwith .env file variablesVariables castingUrl variables exploded to django specific package settingsOptional support for Docker-style file based config variables (useenviron.FileAwareEnvinstead ofenviron.Env)Project Informationdjango-environis released under theMIT / X11 License,
its documentation lives atRead the Docs,
the code onGitHub,
and the latest release onPyPI.It’s rigorously tested on Python 3.5+, and officially supports
Django 1.11, 2.2, 3.0, 3.1, 3.2 and 4.0.If you’d like to contribute todjango-environyou’re most welcome!SupportShould you have any question, any remark, or if you find a bug, or if there is
something you can’t do with thedjango-environ, pleaseopen an issue.ContributingIf you would like to contribute todjango-environ, please take a look at thecurrent issues.  If there is
a bug or feature that you want but it isn’t listed, make an issue and work on it.How to ContributeCheck for open issues or open a fresh issue to start a discussion around a
feature idea or a bug.Forkthe repositoryon GitHub
to start making your changes to thedevelopbranch (or branch off of it).Write a test which shows that the bug was fixed or that the feature works as
expected.Send a pull request and bug the maintainer until it gets merged and published.Release Informationv0.9.0 - 15-June-2022AddedAdded support for Postgresql cluster URI#355.Added support for Django 4.0#371.Added support for prefixed variables#362.Amended documentation.DeprecatedEnv.unicode()is deprecated and will be removed in the next
major release. UseEnv.str()instead.ChangedAttach cause toImproperlyConfiguredexception#360.FixedFixed_cast_urlstrunquoting#357.Fixed documentation regarding unsafe characters in URLs#220.Fixedenviron.Path.__eq__()to compare paths correctly#86,#197.Full changelog.Security PolicyReporting a VulnerabilityIf you discover a security vulnerability withindjango-environ, please
send an e-mail to Serghei Iakovlev viaegrep@protonmail.ch. All security
vulnerabilities will be promptly addressed.Creditsdjango-environwas initially created byDaniele Faragliaand currently maintained bySerghei Iakovlev.A full list of contributors can be found inGitHub.AcknowledgmentsThe existence ofdjango-environwould have been impossible without these
projects:rconradharris/envparsejazzband/dj-database-urlmigonzalvar/dj-email-urlghickman/django-cache-urldstufft/dj-search-urljulianwachholz/dj-config-urlnickstenning/honchorconradharris/envparse