DotEnvPlus
Reads key-value pairs from a .env file with automatic type conversion and variable interpolation.
Zero dependencies, native Python 3.10+.
Values are returned as a dictionary-like object, so .items(), .keys(), .values(), and all standard dict operations work out of the box.
Installing
You need Python >=3.10 to use this library.
pip install dotenvplus
Usage
# .env
KEY1=value
KEY2=123
KEY3=true
from dotenvplus import DotEnv
env = DotEnv(".env")
env["KEY1"] # "value"
env["KEY2"] # 123
env["KEY3"] # True
Type conversion
Values are automatically converted to the appropriate Python type:
| .env value | Python type | Example |
|---|---|---|
hello |
str |
"hello" |
"123" |
str |
"123" |
123 |
int |
123 |
12.34 |
float |
12.34 |
true / false |
bool |
True / False |
null / none / nil / undefined |
None |
None |
Quoting a value (single or double quotes) forces it to remain a string regardless of its content.
Variable interpolation
Reference other keys or system environment variables using ${VAR} or $VAR:
HOST=localhost
PORT=5432
DATABASE_URL=postgres://${HOST}:${PORT}/mydb
REPLICA_URL=postgres://$HOST:$PORT/replica
env["DATABASE_URL"] # "postgres://localhost:5432/mydb"
env["REPLICA_URL"] # "postgres://localhost:5432/replica"
Multiline values
Wrap a value in quotes and span it across multiple lines:
PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEA...
-----END RSA PRIVATE KEY-----"
env["PRIVATE_KEY"] # "-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEA...\n-----END RSA PRIVATE KEY-----"
Constructor options
# Returns None instead of raising KeyError for missing keys
env = DotEnv(".env", handle_key_not_found=True)
env["MISSING"] # None
# Loads all values into os.environ (non-strings are converted to strings)
env = DotEnv(".env", update_system_env=True)
# Don't overwrite keys already set in os.environ (useful as a dev fallback)
env = DotEnv(".env", update_system_env=True, override=False)
# Custom file encoding (defaults to utf-8)
env = DotEnv(".env", encoding="latin-1")
TypedDict support
For full type hint support, define a TypedDict and use as_typed():
from typing import TypedDict
from dotenvplus import DotEnv
class MyEnv(TypedDict):
HOST: str
PORT: int
DEBUG: bool
env: DotEnv[MyEnv] = DotEnv(".env")
typed = env.as_typed()
typed["PORT"] # typed as int
Metadata
Release files for dotenvplus 0.2.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 |
|---|---|---|---|---|
| dotenvplus-0.2.1.tar.gz | 8.5 kB | Without provenance | Details for dotenvplus-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dotenvplus-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for dotenvplus-0.2.1-py3-none-any.whl |
Total release size: 14.4 kB
Release files / dotenvplus-0.2.1.tar.gz
| Download URL | dotenvplus-0.2.1.tar.gz |
|---|---|
| Size | 8.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ef1c79ad4bcfc8a770257c057a91a88a0d5b2ec52957be236746139dc3b1be26
|
|
BLAKE2b-256 checksum How to use checksums |
db39e9032058b0b9bf6bfd073152de57405a0735f8fd1ddaf4f6d4814f6ca282
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / dotenvplus-0.2.1-py3-none-any.whl
| Download URL | dotenvplus-0.2.1-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
069870745047a9ca81bb306f07bda85833a86d4d11e40541118624b56b56e9b4
|
|
BLAKE2b-256 checksum How to use checksums |
912dc6b50e5df9ccbe19537e3951e5028f4ea1e9597aad53c79364520c0dfb4e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for dotenvplus 0.2.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.