Skip to main content

Validate .env files against a schema with secret strength checking

Project description

envguard

Validate .env files against a schema, with secret-strength heuristics, drift detection between environments, and a CI-friendly CLI. Zero runtime dependencies — pure Python 3.8+.

Install

pip install dotenv-lint
# dev tools
pip install -e .[dev]

The PyPI distribution is named dotenv-lint because envguard and similar variants were taken / blocked by PyPI's name-similarity filter. The import name (envguard) and CLI command (envguard) are unchanged.

Quick start

Declare a schema in .env.schema.toml:

[DATABASE_URL]
type     = "url"
required = true

[PORT]
type     = "int"
required = true
range    = [1024, 65535]

[JWT_SECRET]
type        = "str"
required    = true
secret      = true
min_length  = 32

Validate from the CLI:

envguard validate .env --schema .env.schema.toml
envguard validate .env --schema .env.schema.toml --format json
envguard validate .env --schema .env.schema.toml --strict --exit-on-fail
envguard secrets .env
envguard compare .env.development .env.production
envguard scaffold .env > .env.schema.toml

Or from Python:

from envguard import validate

result = validate(env_file=".env", schema=".env.schema.toml")
if not result.is_valid:
    for err in result.errors:
        print(err.code, err.message)
    raise SystemExit(1)

Exit codes

Code Meaning
0 All checks passed
1 One or more errors found
2 One or more warnings (no errors)
3 File not found or unreadable

Schema format

TOML is the primary format (.env.schema.toml); JSON is also accepted (.env.schema.json). The built-in TOML reader is a constrained subset sufficient for the schema layout — top-level tables containing scalars, booleans, and single-line arrays. If you need richer TOML syntax, switch to JSON.

Supported types: str, int, float, bool, url, email, list, json, path, uuid. Constraints per key: required, default, description, secret, choices, range, schemes (URLs), min_length, max_length, must_exist (paths).

Secret strength

When secret = true, EnvGuard runs five heuristics: minimum-length, Shannon-entropy, blocklist, sequential/repeated/keyboard-walk patterns, and all-same-case. Findings come back as WEAK_SECRET / PLAINTEXT_SECRET_PATTERN warnings with HIGH/MEDIUM/LOW severity.

Pre-commit hook

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/FaraiMacheka/envguard
    rev: v1.0.0
    hooks:
      - id: envguard
        args: [".env", "--schema", ".env.schema.toml", "--exit-on-fail"]

The hook calls envguard validate with the args you supply, so point it at whichever .env and schema your repo uses.

Security

For vulnerability reports, see SECURITY.md.

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

dotenv_lint-1.0.0.tar.gz (35.4 kB view details)

Uploaded Source

Built Distribution

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

dotenv_lint-1.0.0-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

File details

Details for the file dotenv_lint-1.0.0.tar.gz.

File metadata

  • Download URL: dotenv_lint-1.0.0.tar.gz
  • Upload date:
  • Size: 35.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dotenv_lint-1.0.0.tar.gz
Algorithm Hash digest
SHA256 eb39df227d4159101a0a01e96ec579d339ec2ffd3326b6dedfc2404640bfbf00
MD5 3b76ef25afe2a01b7d459824ad068aea
BLAKE2b-256 506902abd7771cb17e9014185ff2667ddfa67833716da6780c7238a8eca881fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for dotenv_lint-1.0.0.tar.gz:

Publisher: release.yml on FaraiMacheka/envguard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dotenv_lint-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: dotenv_lint-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 20.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dotenv_lint-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ab1b9d0d304b11806ef7572c116e979d3c0c2c215280966973f3a104a3d4ded5
MD5 6248f2efd9c23656fcd124acce97c03e
BLAKE2b-256 d34efc60c79f9c74dc2db59d9df32026213b0dd9468b5b29a430dcc8e77ac4f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for dotenv_lint-1.0.0-py3-none-any.whl:

Publisher: release.yml on FaraiMacheka/envguard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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