Declare machine-readable .env schemas, then validate them in one command.
- Avoid surprises like missing
DATABASE_URLin staging. - Reject
BETA_TOGGLE=appleswhen a schema forbids it. - Get one human-friendly table or one
--jsonpayload for GitHub Actions and other CI. - Keep one source of truth inside JSON or YAML so reviewers don't have to run the app to trust the required variables.
envguard ships a small CLI that validates .env files against schemas instead of relying on ad-hoc shell scripts or one-off assertions in application code. A schema file declares each variable as JSON or YAML, and envguard check reports issues before code ships.
git clone https://github.com/felixhartmannnn/envguard.git
cd envguard
python -m venv .venv
source .venv/bin/activate
pip install -e '.[dev]'pip install envguard# Generate a starter schema in the current project.
envguard init --output envguard.schema.json
# Point it at the schema and your .env file.
envguard check envguard.schema.jsonScaffold a starter JSON schema with common fields.
envguard init --output envguard.schema.ymlValidate the env file declared in the schema.
# Pretty table output for local use
envguard check envguard.schema.json
# Machine-readable JSON output for scripts and CI
envguard check envguard.schema.json --json
# Override the env file path without changing the schema source.
envguard check envguard.schema.json --env-file .env.stagingUseful flags:
--jsonreturns a stable JSON payload and exits non-zero on issues, making it easy to gate CI.--env-fileswaps the env source at runtime.--project-rootpoints at a monorepo package instead of the current working directory.--helpcovers global and subcommand options.
Use JSON or YAML. The top level can be an object with a fields map, or the map itself if source is left as .env.
fields:
DATABASE_URL:
required: true
kind: string
description: "SQLAlchemy-style database URL."
PORT:
required: true
kind: int
allowed: ["3000", "8080"]
description: "HTTP port used by the API server."
ENABLE_NEW_DASHBOARD:
required: false
kind: bool
default: false
description: "Toggle the new operator UI."
source: .envSupported field attributes:
required: boolkind: string | int | float | bool | jsondefault: anymin_lengthandmax_length: intpattern: regexallowed: list[str]forbidden: list[str]description: string
Declare a field as a bare string for the common case.
{
"API_KEY": "string"
}Shorthand kind aliases map loosely: str, string, text become string; bool and boolean become bool; json, object, list, and array become json.
name: envguard
on: [pull_request]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- run: pip install envguard
- run: envguard check envguard.schema.json --json --env-file .env.exampleenvguard/
src/envguard/
__init__.py
cli.py
schema.py
checks.py
report.py
tests/
docs/
pyproject.toml
cli, python, dotenv, env-validation, developer-tools, envguard, ci
Open an issue or pull request. Add tests alongside behavior changes, and keep the public API coverage in src/envguard/__init__.py.
MIT. See LICENSE for details.
Source and issues: https://github.com/felixhartmannnn/envguard