envguard
Validate your environment variables before your app crashes
The Problem
Your .env file has a typo. You won't know until your app crashes at 3 AM in production.
DATABSE_URL=... # typo → app starts → crashes 2 hours later on first DB call
SECRET_KEY= # empty → auth silently broken
DEBUG=maybe # not a boolean → who knows what happens
The Solution
pip install envguard-check
Check everything before your app starts:
from envguard import guard
# App won't start until all vars are valid
guard(
DATABASE_URL="url",
REDIS_URL="url",
SECRET_KEY="str",
DEBUG="bool",
PORT="int",
)
If anything is wrong, you get a clear error and the app refuses to start:
Environment validation failed:
✗ MISSING: DATABASE_URL is required but not set
✗ TYPE: PORT='abc' is not a valid integer
✗ TYPE: DEBUG='maybe' is not a valid boolean
3 error(s) found. Fix your .env file and try again.
Features
Type Validation
from envguard import check_env, EnvVar
check_env([
EnvVar(name="PORT", type="int"), # must be integer
EnvVar(name="RATE", type="float"), # must be float
EnvVar(name="DEBUG", type="bool"), # true/false/1/0/yes/no
EnvVar(name="API_URL", type="url"), # must start with http(s)://
EnvVar(name="ADMIN_EMAIL", type="email"), # must contain @ and domain
])
Choices
check_env([
EnvVar(name="ENV", choices=["development", "staging", "production"]),
EnvVar(name="LOG_LEVEL", choices=["DEBUG", "INFO", "WARNING", "ERROR"]),
])
Pattern Matching
check_env([
EnvVar(name="STRIPE_KEY", pattern=r"^sk_(live|test)_"),
EnvVar(name="AWS_REGION", pattern=r"^[a-z]{2}-[a-z]+-\d$"),
])
Defaults
check_env([
EnvVar(name="PORT", type="int", default="8000"),
EnvVar(name="DEBUG", type="bool", default="false"),
])
Optional Variables
check_env([
EnvVar(name="SENTRY_DSN", required=False), # won't fail if missing
])
Minimum Length
check_env([
EnvVar(name="SECRET_KEY", min_length=32), # must be at least 32 chars
])
Quick Start with guard()
The guard() function is a one-liner shorthand:
from envguard import guard
guard(
DATABASE_URL="url",
REDIS_URL="url",
SECRET_KEY="str",
DEBUG="bool",
)
Zero Dependencies
envguard uses only Python standard library. No bloat.
License
MIT
Release files for envguard-check 0.1.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 | |
|---|---|---|---|
| envguard_check-0.1.1.tar.gz | 5.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| envguard_check-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.0 kB
Release files / envguard_check-0.1.1.tar.gz
| Download URL | envguard_check-0.1.1.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e9b50f332547bbcf373ea52a997de018856be3fef1afb7104d0f06cda62e6d74
|
|
BLAKE2b-256 checksum How to use checksums |
f5ae75711bf6be0eea866d1a81c3b00ce281ce1f6aeec5a7f7ebb77615aaf191
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / envguard_check-0.1.1-py3-none-any.whl
| Download URL | envguard_check-0.1.1-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2a63bc418f835832c333f721fc1fbc37f1c5db53b7f28b7265ac7d39ff777655
|
|
BLAKE2b-256 checksum How to use checksums |
532ffc6bc575fcd0bb1cd262b7da6c441ee161c2316f6dcc68ff7ee4f76ae80c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|