read an env file and export to os.environ
Project description
python-readenv
readenv
makes it easy to automatically load environment variables from .env
file(s) and put into os.environ
.
Install
$ pip install python-readenv
Getting started
You can automatically load at startup time with the helper import import readenv.loads
,
which try to locate and load the first env file found from your current working directory up to
root.
readenv.readenv.loads
will search for .env
and .env.local
files by default.
Automatic load
You can automatically load at startup time with the helper import
import readenv.loads
...
which try to locate and load the first env file found from your current working directory up to root.
Manually load
Alternatively, you can customize which files readenv
should search and load
from readenv import readenv
readenv.loads("myenv", "myenv.local")
Examples
Django integration
Put the helper import as first place
manage.py
#!/usr/bin/env python3
import readenv.loads # noqa: F401 isort:skip
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
wsgi.py
import readenv.loads # noqa: F401 isort:skip
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
application = get_wsgi_application()
asgi.py
import readenv.loads # noqa: F401 isort:skip
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
application = get_asgi_application()
Project details
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 python_readenv-0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e90fce7ae33d72d8f1742f29c20f28522f7d29d79ba5a8fcaa2fbc091bb1494 |
|
MD5 | bc30848c625a41427c6b97721f15e6a0 |
|
BLAKE2b-256 | 010d9aff12c28ce0bc7608832e00ae157efd142b4dbe1b95e9c371d6c3aae4b6 |