Skip to content

Repository files navigation

autoread-dotenv

Testing Linting Read the Docs Codecov PyPi Package MIT License

autoread-dotenv parses your .env file when starting any venv-based Python process:

Demo

Installation

Install with uv (preferred):

> uv add autoread-dotenv

If you are using Poetry:

> poetry add autoread-dotenv

Install via pip:

> bin/pip install autoread-dotenv

Set up a local development environment

> just install

Usage

The only thing left to do for you is the create a .env in the root of your project.

Registered sitecustomize-entrypoint

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_RUN

Avoid overriding existing environments variables

By 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.

Overriding where the .env-file is looked up

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.env

Performance

autoread-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.

Compatibility

Python Version PyPI - Implementation

autoread-dotenv works on Python 3.9+, including PyPy3. Tested until Python 3.14.

Notable dependencies

About

Autoread the .env-file for in-project virtualenvs

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

4 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages