Skip to main content

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 env and your .env is loaded automatically.

Metadata

Release files for pureenv 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pureenv 0.4.1
File Size Uploaded Provenance Actions
pureenv-0.4.1.tar.gz 6.2 kB Without provenance Details for pureenv-0.4.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pureenv 0.4.1
File Interpreter ABI Platform Actions
pureenv-0.4.1-py3-none-any.whl Python 3 none any Details for pureenv-0.4.1-py3-none-any.whl

Total release size: 11.3 kB

Release files / pureenv-0.4.1.tar.gz

Download URL pureenv-0.4.1.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6284f7694d5387f26f5de151adbce8da0a37542258dc6f5137a3d03d8aee2620
BLAKE2b-256 checksum
How to use checksums
6ec52a4ed21d153e9a36f81e5b01d496d17c3fc137596a714af7e5b2c84f1e78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / pureenv-0.4.1-py3-none-any.whl

Download URL pureenv-0.4.1-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eb30dfe4206d1a55b6575a3efa35093a80cafdaed350f830ec355a5bf707f34c
BLAKE2b-256 checksum
How to use checksums
db6b78bace6cd6a47e73e884d6525b10d5f6b876c04638f6d5c61bc75f535dbd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for pureenv 0.4.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page