dotvar: Smarter Environment Variable Management for Python
dotvar is a Python module that improves upon traditional .env loaders by providing automatic loading and native variable interpolation, solving the major shortcomings of python-dotenv.
Differences from python-dotenv:
- ✅ Built-in Interpolation: Reference other variables within
.env. - ✅ Option to Auto-load: The option to load upon import, with no extra calls.
- ✅ Strict Mode: Catch missing
.envfiles early. - ✅ No Dependencies: Pure Python, standard library only.
- ✅ Lightweight & Fast: Minimal footprint, optimized load time.
How to Use
- place a
.envin your current folder - you can run
load_envor simply importdotvar.auto_loadwhich has the side-effect of callingload_envimport dotvar.auto_load # noqa
Alternatively, there is also astrictmode, that raises an error if an environment file is not found.import dotvar.auto_load_strict # noqa
Alternative syntax
If the import side-effect is undesirable, you can import the load_env function and call it imperatively.
The import here will NOT have a side-effect.
from dotvar import load_env
load_env(strict=False)
The strict flag defautls to False.
The Problems with python-dotenv
While python-dotenv is widely used, it has two significant limitations:
- It does not support automatic loading upon import.
- It lacks variable interpolation, so environment variables cannot reference other variables within the same
.envfile.
For example, the following will not be correctly resolved using python-dotenv:
BASE_URL=https://api.example.com
API_ENDPOINT=${BASE_URL}/v1/
import os
print(os.environ.get("API_ENDPOINT")) # Returns "${BASE_URL}/v1/" instead of the resolved value
Introducing dotvar
dotvar solves these issues by:
- Supporting native variable interpolation with
${VAR_NAME}syntax. - Offering an auto-load entrypoint: just import
dotvar.auto_load. - Providing a strict mode (
dotvar.auto_load_strict) that raises an error if.envis not found.
Installation and Examples
pip install dotvar # supports Python 3.7+
An Example:
Place a .env file in your project root:
BASE_URL=https://api.example.com
API_ENDPOINT=${BASE_URL}/v1/
API_KEY=s3cr3t_api
Then in your Python code:
# noinspection PyUnresolvedReferences
import dotvar.auto_load # noqa
import os
print(os.environ["BASE_URL"]) # https://api.example.com
print(os.environ["API_ENDPOINT"]) # https://api.example.com/v1/
print(os.environ["API_KEY"]) # s3cr3t_api
To use strict mode:
import dotvar.auto_load_strict # noqa
Development
This project uses uv for dependency management.
# Set up environment
uv sync
# Run all tests
uv run pytest
# Run with coverage
uv run pytest --cov=dotvar --cov-report=term-missing
License
MIT License
Metadata
Release files for dotvar 0.1.12
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 |
|---|---|---|---|---|
| dotvar-0.1.12.tar.gz | 32.9 kB | Without provenance | Details for dotvar-0.1.12.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dotvar-0.1.12-py3-none-any.whl | Python 3 | none | any | Details for dotvar-0.1.12-py3-none-any.whl |
Total release size: 36.9 kB
Release files / dotvar-0.1.12.tar.gz
| Download URL | dotvar-0.1.12.tar.gz |
|---|---|
| Size | 32.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
033bea448067b29be230b0fbf3c97fa5ff4a875471ddb1cb505049698c50e774
|
|
BLAKE2b-256 checksum How to use checksums |
76d8d8ef6b289aec21bfaae97ca86068403bf541e5d1c5c7c14897e06d5d1beb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.3
|
Release files / dotvar-0.1.12-py3-none-any.whl
| Download URL | dotvar-0.1.12-py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9e11ad6cd0a6341c824ff70bd4ca7e9bb2f3e64df73a51e86b87d61bfb06272a
|
|
BLAKE2b-256 checksum How to use checksums |
26b0ae474bae166b2f00f8288cd47ac9acef3e0d30bdab5457776caa1746a8eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.3
|
Security for dotvar 0.1.12
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.