autoread-dotenv parses your .env file when starting any venv-based Python process:
Install with uv (preferred):
> uv add autoread-dotenvIf you are using Poetry:
> poetry add autoread-dotenvInstall via pip:
> bin/pip install autoread-dotenv> just installThe only thing left to do for you is the create a .env in the root of your project.
The autoread_dotenv.entrypoint-function is registered as a sitecustomize-entrypoint in our pyproject.toml_:
[project.entry-points.sitecustomize]
autoread_dotenv = "autoread_dotenv:entrypoint"Sitecustomize and all its registered entrypoints will be executed at the start of every python-process. For more information, please see sitecustomize-entrypoints
entrypoint() never raises for a configuration problem (a missing, unreadable or
un-loadable .env, or a missing python-dotenv): it warns and carries on, so it cannot
break interpreter startup. To check afterwards whether loading actually succeeded, read
autoread_dotenv.last_load_status (a LoadStatus enum), which entrypoint() also returns:
import autoread_dotenv
from autoread_dotenv import LoadStatus
if autoread_dotenv.last_load_status is not LoadStatus.LOADED:
... # LoadStatus.MISSING / DOTENV_NOT_INSTALLED / LOAD_FAILED / NOT_RUNBy default, your .env-file read by autoread-dotenv will override any pre-existing environment variables.
You can avoid this behaviour by setting AUTOREAD_ENFORCE_DOTENV=0.
By default, autoread-dotenv locates your .env relative to sys.prefix, assuming the
in-project-virtualenv layout described above. For setups that don't follow that convention
(global installs, containers, editable mounts, ...), set AUTOREAD_DOTENV_PATH to the full path
of the .env-file to use instead - it takes precedence and skips the sys.prefix-based lookup
entirely:
> export AUTOREAD_DOTENV_PATH=/etc/myapp/production.envautoread-dotenv runs on the start of every Python process in the venv, so its startup-time
cost is measured and tracked explicitly - see
the performance page for the
current numbers and how to reproduce them.
autoread-dotenv works on Python 3.9+, including PyPy3. Tested until Python 3.14.
