Skip to main content

envproof

Validate environment variables at startup with typed, clear error messages. Zero dependencies. Production-ready.

PyPI version Python versions CI License: MIT Open Source


Every backend app reads environment variables. The standard way fails silently or crashes with a cryptic error deep inside your app at runtime:

# Crashes 10 minutes in, on an obscure code path
db = connect(os.environ["DATABASE_URL"])  # KeyError: DATABASE_URL

# PORT is a string — breaks math silently
port = os.environ["PORT"]  # "8080", not 8080

envproof catches all of this at startup, before your app serves a single request:

from envproof import EnvGuard

class Env(EnvGuard):
    DATABASE_URL: str
    PORT: int = 8080
    DEBUG: bool = False
    ALLOWED_HOSTS: list = []

env = Env()
print(env.PORT)  # 8080 — already an int

If anything is wrong, you get a clear error immediately:

EnvProofError:
Missing required environment variables:
  - DATABASE_URL (str): not set

Invalid environment variable values:
  - PORT: expected int, got 'abc'
  - DEBUG: expected bool, got 'maybe'

All errors reported at once — not one at a time.


Install

pip install envproof

Usage

Recommended: one env.py file in your project

# env.py
from envproof import EnvGuard

class Env(EnvGuard):
    # Required — raises EnvProofError at startup if not set
    DATABASE_URL: str
    SECRET_KEY: str
    API_KEY: str

    # Optional — uses default if not set
    PORT: int = 8080
    DEBUG: bool = False
    LOG_LEVEL: str = "INFO"
    ALLOWED_HOSTS: list = []

env = Env()

Then import env anywhere in your app:

# app.py
from env import env

app.run(port=env.PORT, debug=env.DEBUG)
# database.py
from env import env

db = connect(env.DATABASE_URL)

One-liner style (no subclass needed)

from envproof import guard

env = guard(DATABASE_URL=str, PORT=int, DEBUG=bool)
print(env.DATABASE_URL)

Works great with python-dotenv

from dotenv import load_dotenv
load_dotenv()          # loads .env file into environment

from env import env    # envproof validates it

Supported types

Type Example env value Python value
str hello "hello"
int 8080 8080
float 3.14 3.14
bool true, 1, yes, on True
bool false, 0, no, off False
list localhost,example.com ["localhost", "example.com"]

Why envproof?

envproof os.environ pydantic-settings
Type coercion Yes No Yes
Clear error messages Yes No Partial
Zero dependencies Yes Yes No (~2MB)
Fail fast at startup Yes No Yes
Works anywhere Yes Yes Pydantic only

vs pydantic-settings: great library, but pulls in Pydantic (~2MB). envproof is a single file with zero dependencies — ideal for serverless functions, lightweight containers, or any project that doesn't already use Pydantic.


Production use

envproof is designed for production. The "fail fast" pattern — crashing at startup rather than during a request — is standard practice in production backend systems. Your app either starts correctly or doesn't start at all. No surprises mid-flight.

Used in: FastAPI apps, Flask apps, Django projects, CLI tools, serverless functions, Docker containers.


Open Source

envproof is MIT licensed and open for contributions. See CONTRIBUTING.md for how to get started.

Things we'd love help with:

  • New types: dict, Path, Enum
  • Framework integrations (FastAPI lifespan hooks, Django AppConfig.ready())
  • Better error formatting
  • More test coverage

Open an issue or submit a PR — all contributions welcome.


License

MIT © Sufiyan Khan

Metadata

Release files for envproof 0.2.0

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

Source distribution (sdist)

Source distribution for envproof 0.2.0
File Size Uploaded
envproof-0.2.0.tar.gz 6.1 kB Details

Built distribution (wheel)

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

Total release size: 11.2 kB

Release files / envproof-0.2.0.tar.gz

Download URL envproof-0.2.0.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
af312124db55c146e4ac7ec26effaf161c59540139edf2ac50574888d5890358
BLAKE2b-256 checksum
How to use checksums
1471be916e257433c0c034914ad20ea4e96e3f32eb246de2146fc34f3277406d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Release files / envproof-0.2.0-py3-none-any.whl

Download URL envproof-0.2.0-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b53511640630f6660d414a21a2fa242d31caa1c6ebfda8f52514035bd5a7d9bb
BLAKE2b-256 checksum
How to use checksums
9d093265a717f14708e08058edaba30789c068582982b5af7452dbdd38be0ef2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

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