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.
By default it will search for .env and .env.local files.
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.
Manual load
Alternatively, you can customize which files readenv should search and load
import readenv
readenv.load("myenv", "myenv.local")
mypy integration
If you need to load the environment from mypy you could add
[mypy]
plugins = readenv.mypy
in your mypy.ini or setup.cfg file.
pyproject.toml configuration is also supported:
[tool.mypy]
plugins = ["readenv.mypy"]
Custom environment
You can create your own environment
import readenv
env = readenv.Environ()
or start with the current environ copy
import copy
import os
import readenv
env = Environ(copy.deepcopy(os.environ))
Examples
Django integration
Put the helper import as first place
manage.py
#!/usr/bin/env python3
import readenv.loads # noqa: F401 isort:skip
import sys
if __name__ == "__main__":
readenv.setdefault("DJANGO_SETTINGS_MODULE", "myproject.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
from django.core.wsgi import get_wsgi_application
readenv.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
application = get_wsgi_application()
asgi.py
import readenv.loads # noqa: F401 isort:skip
from django.core.asgi import get_asgi_application
readenv.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
application = get_asgi_application()
Metadata
Release files for python-readenv 0.7.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| python_readenv-0.7.1.tar.gz | 9.4 kB | Without provenance | Details for python_readenv-0.7.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_readenv-0.7.1-py3-none-any.whl | Python 3 | none | any | Details for python_readenv-0.7.1-py3-none-any.whl |
Total release size: 20.0 kB
Release files / python_readenv-0.7.1.tar.gz
| Download URL | python_readenv-0.7.1.tar.gz |
|---|---|
| Size | 9.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9f862db7598a9cb723944d1140d2dc192a732013f66cb4a3127a006aa7dd3e18
|
|
BLAKE2b-256 checksum How to use checksums |
a4ab92114a91a84674c21e8f8ff915a8a2bacbe44ddb7b2eff215aafe68cd888
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.0
|
Release files / python_readenv-0.7.1-py3-none-any.whl
| Download URL | python_readenv-0.7.1-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3d9dd9e25e6718a2fdd1effe3b2b1597881a44bfa1e1872f13046addbdd950e3
|
|
BLAKE2b-256 checksum How to use checksums |
eb490d1187d3d7df6bd58b6dd3103475c06c63b042110eacf0fe07f0f5dfe020
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.0
|
Security for python-readenv 0.7.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.