Skip to main content

Catch missing .env variables before they crash production

Project description

dotenvguard

PyPI version Downloads Python 3.12+ CI License: MIT

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dotenvguard-0.1.1.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dotenvguard-0.1.1-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file dotenvguard-0.1.1.tar.gz.

File metadata

  • Download URL: dotenvguard-0.1.1.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.7

File hashes

Hashes for dotenvguard-0.1.1.tar.gz
Algorithm Hash digest
SHA256 870a2abeca7080edb73e5604f0ef57c54dfc90476b4f16849cf30657de7b501c
MD5 3e85d56cb85f2915340b258aa6ccf220
BLAKE2b-256 7d6f881a2cfc184646d547cf01ffd3d400ae98546dc03c48bbe89868e07f1420

See more details on using hashes here.

File details

Details for the file dotenvguard-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for dotenvguard-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 23d11027196a83382066052626ae91ecf35ac472030c2020a54e7f8719c3d74c
MD5 06202c97b87a629c2c63e086a4ca6e11
BLAKE2b-256 7ca1b66e11f5c0a1465abadd8d6d31dc900ece2b103018bc03d5922bb37def1d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page