Typed environment variable parsing for Python. Zero dependencies. Pure stdlib.
Project description
pureenv
Typed environment variable parsing for Python. Zero dependencies. Pure stdlib.
The Problem
Every Python project ends up writing this:
PORT = int(os.environ.get("PORT", 8080))
DEBUG = os.environ.get("DEBUG", "false").lower() == "true"
DB_URL = os.environ["DATABASE_URL"] # KeyError with no helpful message
Manual casting. No validation. Cryptic error. Every. Single. Project.
The solution
from pureenv import env # .env file auto-loaded if it exists
PORT = env("PORT", default="8080") # no casting needed
PORT = env.int("PORT", default=8080) # or typed
DEBUG = env.bool("DEBUG", default=False)
DB_URL = env.str("DATABASE_URL", required=True)
Typed. Validated. Clear errors when something is wrong.
Install
pip install pureenv
Usage
Create a .env file in your project root:
DATABASE_URL=postgres://localhost/mydb
DEBUG=true
PORT=8080
Then just import and use - no setup needed:
from pureenv import env
# strings - without casting (return str)
APP_NAME = env("APP_NAME", default="myapp")
# explicit str
DB_HOST = env.str("DB_HOST", default="localhost")
# numbers
PORT = env.int("PORT", default=8080)
RATIO = env.float("RATIO", default=0.5)
# booleans - accepts "true/false", "1/0", "yes/no", "y/n", "on/off"
DEBUG = env.bool("DEBUG", default=False)
# required - raises a clear error if missing
DB_URL = env.str("DATABASE_URL", required=True)
# grouping related env variables
with env.prefix("DB_"):
DB_HOST = env("HOST", default="localhost") # reads DB_HOST
DB_PORT = env("PORT", default="5432") # reads DB_PORT
DB_NAME = env("NAME", default="mydb") # reads DB_NAME
Why not environs or python-dotenv?
| pureenv | python-dotenv | environs | |
|---|---|---|---|
| Typed casting | ✅ | ❌ | ✅ |
| Zero dependencies | ✅ | ✅ | ❌ |
| Required validation | ✅ | ❌ | ✅ |
| Loads .env file | ✅ | ✅ | ✅ |
| Auto-loads .env | ✅ | ❌ | ❌ |
| Prefix grouping | ✅ | ❌ | ✅ |
✅ Auto-loads means no setup needed — just
from pureenv import envand your.envis loaded automatically.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pureenv-0.4.1.tar.gz.
File metadata
- Download URL: pureenv-0.4.1.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6284f7694d5387f26f5de151adbce8da0a37542258dc6f5137a3d03d8aee2620
|
|
| MD5 |
5aead910a99501d7fc2a34cd86638921
|
|
| BLAKE2b-256 |
6ec52a4ed21d153e9a36f81e5b01d496d17c3fc137596a714af7e5b2c84f1e78
|
File details
Details for the file pureenv-0.4.1-py3-none-any.whl.
File metadata
- Download URL: pureenv-0.4.1-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb30dfe4206d1a55b6575a3efa35093a80cafdaed350f830ec355a5bf707f34c
|
|
| MD5 |
fef03cdcfbed4ce360f6b2138bdb843e
|
|
| BLAKE2b-256 |
db6b78bace6cd6a47e73e884d6525b10d5f6b876c04638f6d5c61bc75f535dbd
|