A strict, CI-ready environment variable validator with schema enforcement, drift detection, and secret scanning.
Project description
env-check
A strict, CI-ready environment variable validator with schema enforcement, drift detection, and secret scanning.
Stop broken .env files, silent misconfigurations, and leaked secrets before they reach production.
๐ฏ Why env-check exists
Most projects rely on .env files that:
- โ Drift between environments โ dev, staging, and prod configurations diverge
- โ Miss required variables โ critical settings are missing until runtime
- โ Contain invalid values โ wrong formats, out-of-range numbers, invalid URLs
- โ Accidentally leak secrets โ API keys and passwords committed to repos
- โ Fail silently until runtime โ errors only surface in production
Existing tools validate presence.
env-check validates correctness, consistency, and safety.
โจ What env-check does
- โ Validates .env files against a schema โ enforce structure and types
- โ Enforces required keys and patterns โ regex, enums, ranges, types
- โ Detects environment drift โ compare configurations across environments
- โ Scans for high-risk secrets โ heuristic detection of leaked credentials
- โ Produces CI-friendly output โ JSON format for automation
- โ Fails fast with meaningful exit codes โ integrate seamlessly into pipelines
This is prevention, not cleanup.
๐ฆ Installation
Standard Installation
pip install envcheck-cli
Recommended for CI / Global Usage
pipx install env-check
Development Installation
git clone https://github.com/BinaryBard27/env-check
cd env-check
pip install -e .
๐ Quick Start
Basic Validation
Validate your .env file against a schema:
env-check --schema schema.json --env .env
Strict Mode (Recommended)
Treat warnings as errors and fail on any issues:
env-check --strict
CI-Friendly JSON Output
Get machine-readable output for automation:
env-check --format json
Autofix Missing Keys
Automatically add missing required keys (with backup):
env-check --fix
Using Configuration File
Use a YAML or JSON configuration file:
env-check --config envcheck.yml
๐ Schema Examples
JSON Schema Format
{
"PORT": {
"required": true,
"pattern": "^[0-9]+$",
"type": "int",
"range": "1024-65535"
},
"MODE": {
"required": true,
"enum": ["dev", "staging", "prod"]
},
"API_KEY": {
"required": true,
"secret": true,
"pattern": "^sk-[A-Za-z0-9]{20,}$"
},
"DATABASE_URL": {
"required": true,
"type": "url",
"non_empty": true
},
"LOG_LEVEL": {
"required": false,
"enum": ["DEBUG", "INFO", "WARNING", "ERROR"],
"default": "INFO"
}
}
YAML Configuration Format
variables:
PORT:
required: true
type: int
range: "1024-65535"
MODE:
required: true
enum: ["dev", "staging", "prod"]
API_KEY:
required: true
secret: true
pattern: "^sk-[A-Za-z0-9]{20,}$"
DATABASE_URL:
required: true
type: url
non_empty: true
Schema capabilities:
- โ Enforces presence โ required variables must exist
- โ Prevents invalid values โ type checking, regex patterns, enums
- โ Flags sensitive keys โ secret scanning for leaked credentials
- โ Range validation โ numeric ranges for ports, timeouts, etc.
- โ File existence โ validate file paths exist
- โ URL validation โ ensure URLs are properly formatted
๐ง Available Validators
env-check supports multiple validation types:
| Validator | Description | Example |
|---|---|---|
required |
Variable must be present | "required": true |
type |
Type checking (int, float, bool, url) | "type": "int" |
pattern |
Regex pattern matching | "pattern": "^[0-9]+$" |
enum |
Value must be in allowed list | "enum": ["dev", "prod"] |
range |
Numeric range validation | "range": "1-100" |
non_empty |
Value cannot be empty string | "non_empty": true |
file_exists |
File path must exist | "file_exists": true |
secret |
Flag for secret scanning | "secret": true |
๐ CI/CD Integration
GitHub Actions
name: Validate Environment
on: [push, pull_request]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install env-check
run: pip install env-check
- name: Validate environment
run: env-check --strict --format json
GitLab CI
validate_env:
image: python:3.9
before_script:
- pip install env-check
script:
- env-check --strict --format json
CircleCI
jobs:
validate:
docker:
- image: cimg/python:3.9
steps:
- checkout
- run: pip install env-check
- run: env-check --strict --format json
If validation fails:
- โ CI fails immediately
- ๐ Deployment stops
- ๐ซ Broken config never ships
๐ Exit Codes
| Code | Meaning | When It Occurs |
|---|---|---|
0 |
Validation passed | All checks pass |
1 |
Validation errors | Missing required vars, invalid values |
2 |
Schema errors | Invalid schema file, parsing errors |
3 |
Secret risk detected | Potential secrets found in .env |
Designed for automation โ use exit codes in your CI/CD pipelines.
๐ How env-check Compares
| Feature | env-check | check-env | envalid (Node) |
|---|---|---|---|
| Schema Validation | โ | โ | โ |
| Drift Detection | โ | โ | โ |
| Secret Scanning | โ | โ | โ |
| CI Output (JSON) | โ | โ | โ |
| Type Validation | โ | โ | โ |
| Range Validation | โ | โ | โ |
| File Existence | โ | โ | โ |
env-check focuses on preventing configuration failure, not just detecting missing keys.
๐ Security & Limitations
Secret Detection
env-check provides basic secret detection through schema flags. Understanding its limitations is critical for security-conscious teams.
What env-check does:
- Flags environment variables marked with
secret: truein your schema - Returns exit code 3 when secrets are detected
- Provides preventive checks before deployment
What env-check does NOT do:
- No automatic secret scanning โ Only variables explicitly marked
secret: truein the schema are flagged - No pattern matching โ Does not automatically detect secret patterns or signatures
- Not a forensic tool โ Cannot detect secrets already committed or leaked
- Not a replacement for dedicated scanners โ Should be used alongside tools like TruffleHog, GitGuardian, or GitHub's secret scanning
Important limitations:
- โ ๏ธ Heuristic-based โ Detection relies on schema flags, not content analysis
- โ ๏ธ False positives possible โ Variables marked as secrets may not actually contain sensitive data
- โ ๏ธ Manual configuration required โ You must explicitly mark variables as secrets in your schema
- โ ๏ธ Preventive only โ Designed to catch mistakes before deployment, not to audit existing repositories
Example:
{
"API_KEY": {
"required": true,
"secret": true
}
}
Only variables with "secret": true will trigger exit code 3. Variables without this flag are not checked for secret patterns.
Drift Detection
What is drift?
Environment drift occurs when configuration files (.env files) diverge between environments (development, staging, production). For example:
- Development has
PORT=3000but production hasPORT=8080 - Staging includes
DEBUG=truebut production is missing it - Different API endpoints are configured across environments
How env-check detects drift: env-check validates each environment file against a shared schema. It does not automatically compare files between environments, but ensures all environments conform to the same validation rules.
What env-check does:
- Validates
.envfiles against a schema to ensure required variables exist - Enforces consistent validation rules across all environments
- Catches missing or invalid variables before deployment
What env-check does NOT do:
- No automatic comparison โ Does not directly compare
.env.devvs.env.prod - No drift visualization โ Does not generate diff reports between environments
- No inference โ Does not guess which variables should differ between environments
Example workflow:
# Validate development environment
env-check --schema schema.json --env .env.dev
# Validate staging environment
env-check --schema schema.json --env .env.staging
# Validate production environment
env-check --schema schema.json --env .env.prod --strict
Each environment is validated independently. To detect actual drift, you would need to run env-check on each environment file and compare results, or use additional tooling.
Example drift detection output: If production is missing a required variable that exists in development:
$ env-check --schema schema.json --env .env.prod
DATABASE_URL | MISSING | CRITICAL | Required variable missing
This indicates drift (missing variable), but env-check does not automatically identify which other environments have this variable.
Best Practices
- โ Use it early in the pipeline โ validate before deployment
- โ Combine with other tools โ use alongside dedicated secret scanners
- โ Review flagged items โ investigate all secret warnings
- โ Keep schemas updated โ maintain schema as your config evolves
๐ Usage Examples
Example 1: Basic Validation
# Create schema.json
cat > schema.json << EOF
{
"DATABASE_URL": {
"required": true,
"type": "url"
},
"API_KEY": {
"required": true,
"secret": true
}
}
EOF
# Validate
env-check --schema schema.json --env .env
Example 2: Strict Mode with JSON Output
env-check --strict --format json > validation-results.json
Example 3: Multiple Environment Validation
# Validate dev environment
env-check --schema schema.json --env .env.dev
# Validate production environment
env-check --schema schema.json --env .env.prod --strict
๐ Troubleshooting
Common Issues
Issue: Config file not found: envcheck.yml
Solution: Create a configuration file or specify the path:
env-check --config path/to/your/config.yml
Issue: Schema validation fails
Solution: Check your schema format. Ensure it's valid JSON or YAML:
# Validate JSON
python -m json.tool schema.json
# Validate YAML
python -c "import yaml; yaml.safe_load(open('schema.yml'))"
Issue: False positives in secret scanning
Solution: Review flagged variables and adjust your schema if needed. Secret scanning is heuristic-based and may require tuning.
๐ค Contributing
Contributions are welcome! We appreciate your help in making env-check better.
Please see CONTRIBUTING.md before submitting PRs.
Ways to Contribute
- ๐ Report bugs
- ๐ก Suggest new features
- ๐ Improve documentation
- ๐ง Add new validators
- ๐งช Write tests
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Links
- Repository: https://github.com/BinaryBard27/env-check
- Issues: https://github.com/BinaryBard27/env-check/issues
- PyPI: https://pypi.org/project/env-check/
Made with โค๏ธ for developers who care about configuration safety.
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 envcheck_cli-1.0.0.tar.gz.
File metadata
- Download URL: envcheck_cli-1.0.0.tar.gz
- Upload date:
- Size: 19.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81e5cfcf408215bc6e33f3d84ce08f94fc6116af7775af4e48d5459670e57aa3
|
|
| MD5 |
ed26b24feb4f53c543c386c5905824a9
|
|
| BLAKE2b-256 |
808949c765aa4700f9f5adcbeea7f76fdc011c8dc275bd48abae0d9a981ec280
|
File details
Details for the file envcheck_cli-1.0.0-py3-none-any.whl.
File metadata
- Download URL: envcheck_cli-1.0.0-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
717a6a747097d50c937839ee7b2a76bc4fba44f5384eecbac77bcc4460e943f9
|
|
| MD5 |
d8d1f55bdda08b9027e5e6db7261d7bd
|
|
| BLAKE2b-256 |
530b78641722fa67748560f7e0943970cf4c9d75717c92e122789f54235c7b1c
|