Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joke2k/django-environ
Django-environ allows you to utilize 12factor inspired environment variables to configure your Django application.
https://github.com/joke2k/django-environ
django hacktoberfest python settings twelve-factor
Last synced: 5 days ago
JSON representation
Django-environ allows you to utilize 12factor inspired environment variables to configure your Django application.
- Host: GitHub
- URL: https://github.com/joke2k/django-environ
- Owner: joke2k
- License: mit
- Created: 2013-04-02T13:50:07.000Z (almost 12 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T10:48:27.000Z (3 months ago)
- Last Synced: 2024-10-29T10:52:08.330Z (3 months ago)
- Topics: django, hacktoberfest, python, settings, twelve-factor
- Language: Python
- Homepage: https://django-environ.rtfd.org
- Size: 777 KB
- Stars: 3,013
- Watchers: 37
- Forks: 316
- Open Issues: 80
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG.rst
- Contributing: CONTRIBUTING.rst
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
- Security: SECURITY.rst
- Authors: AUTHORS.rst
Awesome Lists containing this project
- awesome-humanscape - django-environ - [12 factors 방법론](https://www.12factor.net/)을 지킬수 있도록 환경설정 파일을 따로 관리할 수 있게 해주는 라이브러리 (Django / Environment)
- -awesome-django - django-environ - Environment variables. (Third-Party Packages / Configuration)
- awesome-django - django-environ - Environment variables. (Third-Party Packages / Configuration)
- starred-awesome - django-environ - Django-environ allows you to utilize 12factor inspired environment variables to configure your Django application. (Python)
- best-of-web-python - GitHub - 31% open · ⏱️ 01.09.2023): (Django Utilities)
- best-django-resource - django-environ - Handles environment variables and settings management in Django projects. (Database and ORM)
README
.. raw:: html
django-environ
.. -teaser-begin-
``django-environ`` is the Python package that allows you to use
`Twelve-factor methodology `_ to configure your
Django application with environment variables... -teaser-end-
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:.. -code-begin-
.. code-block:: python
import environ
import osenv = environ.Env(
# set casting, default value
DEBUG=(bool, False)
)# Set the project base directory
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))# Take environment variables from .env file
environ.Env.read_env(os.path.join(BASE_DIR, '.env'))# False if not in os.environ because of casting above
DEBUG = env('DEBUG')# Raises Django's ImproperlyConfigured
# exception if SECRET_KEY not in os.environ
SECRET_KEY = env('SECRET_KEY')# Parse database connection url strings
# like psql://user:[email protected]:8458/db
DATABASES = {
# 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')
}.. -overview-
The idea of this package is to unify a lot of packages that make the same stuff:
Take a string from ``os.environ``, parse and cast it to some of useful python
typed variables. To do that and to use the `12factor `_
approach, some connection strings are expressed as url, so this package can parse
it and return a ``urllib.parse.ParseResult``. These strings from ``os.environ``
are loaded from a ``.env`` file and filled in ``os.environ`` with ``setdefault``
method, to avoid to overwrite the real environ.
A similar approach is used in
`Two Scoops of Django `_
book and explained in `12factor-django `_
article.Using ``django-environ`` you can stop to make a lot of unversioned
``settings_*.py`` to configure your app.
See `cookiecutter-django `_
for a concrete example on using with a django project.**Feature Support**
- Fast and easy multi environment for deploy
- Fill ``os.environ`` with .env file variables
- Variables casting
- Url variables exploded to django specific package settings
- Optional support for Docker-style file based config variables (use
``environ.FileAwareEnv`` instead of ``environ.Env``).. -project-information-
Project Information
===================``django-environ`` is released under the `MIT / X11 License `__,
its documentation lives at `Read the Docs `_,
the code on `GitHub `_,
and the latest release on `PyPI `_.It’s rigorously tested on Python 3.9+, and officially supports
Django 2.2, 3.0, 3.1, 3.2, 4.0, 4.1, 4.2, 5.0, and 5.1.If you'd like to contribute to ``django-environ`` you're most welcome!
.. -support-
Support
=======Should you have any question, any remark, or if you find a bug, or if there is
something you can't do with the ``django-environ``, please
`open an issue `_.