Catch missing .env variables before they crash production
Project description
dotenvguard
You know the drill. Someone adds STRIPE_KEY to .env.example, forgets to mention it, and the next deploy blows up with a KeyError. dotenvguard catches that before it happens.
$ dotenvguard check
dotenvguard
┏━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Variable ┃ Status ┃ Default ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ DATABASE_URL │ ok │ postgres://localhost:5432/mydb │
│ API_KEY │ ok │ │
│ SECRET_TOKEN │ empty │ │
│ REDIS_URL │ MISSING │ redis://localhost:6379 │
│ STRIPE_KEY │ MISSING │ │
└──────────────┴─────────┴────────────────────────────────┘
2 missing variables out of 5 required
Install
pip install dotenvguard
# or with uv
uv tool install dotenvguard
How it works
Point it at a directory. It finds .env and .env.example, compares them, and tells you what's off.
dotenvguard check # current dir
dotenvguard check /path/to/project # somewhere else
dotenvguard check --json # machine-readable output
dotenvguard check --extra # also show vars in .env that aren't in .env.example
Custom file paths if your setup is weird:
dotenvguard check --env .env.local --example .env.template
It picks up .env.example, .env.sample, and .env.template automatically, so most projects just work out of the box.
Drop it in CI
Exits with code 1 when something's missing. That's it.
# GitHub Actions
- run: pip install dotenvguard && dotenvguard check
Or as a pre-commit hook:
repos:
- repo: local
hooks:
- id: dotenvguard
name: dotenvguard
entry: dotenvguard check
language: python
additional_dependencies: [dotenvguard]
pass_filenames: false
What the statuses mean
| Status | What it means |
|---|---|
ok |
Present in .env with a value. You're good. |
MISSING |
In .env.example but not in your .env at all. |
empty |
Key exists but the value is blank. |
extra |
In .env but not in .env.example. Orphaned. |
Handles real .env files
Not just KEY=value. The parser deals with the stuff you actually see in the wild:
DATABASE_URL=postgres://localhost/db # standard
SECRET="value with spaces" # quoted
export API_KEY=sk-1234 # export prefix
DEBUG=true # enable debug mode # inline comments
DSN=postgres://u:p@host/db?ssl=require # equals in values
Why I built this
I got tired of deployments failing because someone added an env var and forgot to tell the team. python-dotenv loads vars but doesn't check if they're all there. pydantic-settings validates at runtime but you need to write a Settings class. I just wanted one command I could run before pushing.
License
MIT
Project details
Release history Release notifications | RSS feed
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 dotenvguard-0.2.0.tar.gz.
File metadata
- Download URL: dotenvguard-0.2.0.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bdde1f310fb4c1e701090c78d9c0ec25152f00037d675241a632274e1bed3da1
|
|
| MD5 |
b7d43efb9f73eda9c1d24286a5032a3a
|
|
| BLAKE2b-256 |
ceabe2aea1a699d9b63b89bf30815f3c7180fd36b0d24b74d879864ca64f016f
|
File details
Details for the file dotenvguard-0.2.0-py3-none-any.whl.
File metadata
- Download URL: dotenvguard-0.2.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2899ef167c5a4b5266a7a3b5160926f557a36af6568cf46e357224c07f0e16e
|
|
| MD5 |
33af0dd9573e3bb852f844096a38a99c
|
|
| BLAKE2b-256 |
74710981a0887f89e7e236efd42faa15e6cd19cd36eca702b55d38763ef701c9
|