Secure environment variable & secrets manager for Python projects
Never accidentally commit your secrets again.
Every Python developer has been there β you push to GitHub, then realize .env is in the commit history. Or you clone a project and spend 20 minutes figuring out which env vars are needed and where to get them.
PyGuard fixes that.
PyGuard is a lightweight CLI tool that:
- Audits your project for exposed secrets and hardcoded credentials
- Validates that all required env vars are present before running your app
- Generates
.env.examplefrom your actual.env(values stripped, keys kept) - Encrypts sensitive
.envfiles for safe sharing with teammates - Checks your git history for accidentally committed secrets
pip install pyguard-cliOr install from source:
git clone https://github.com/Alice699/pyguard.git
cd pyguard
pip install -e .# Audit your current project for exposed secrets
pyguard audit
# Validate all required env vars are set
pyguard validate --schema .env.schema
# Generate a safe .env.example from your .env
pyguard export
# Encrypt your .env for sharing
pyguard encrypt .env --output .env.encrypted
# Decrypt
pyguard decrypt .env.encrypted --output .env
# Scan git history for committed secrets
pyguard history-scan| Command | Description |
|---|---|
pyguard audit |
Scan project files for hardcoded secrets |
pyguard validate |
Check all required env vars are present |
pyguard export |
Generate .env.example from .env |
pyguard encrypt <file> |
AES-256 encrypt an env file |
pyguard decrypt <file> |
Decrypt an encrypted env file |
pyguard history-scan |
Scan git log for leaked secrets |
pyguard init |
Create .env.schema from existing .env |
Define which env vars are required vs optional:
# .env.schema
DATABASE_URL:
required: true
description: "PostgreSQL connection string"
SECRET_KEY:
required: true
description: "App secret key, min 32 chars"
min_length: 32
DEBUG:
required: false
default: "false"
description: "Enable debug mode"
REDIS_URL:
required: false
description: "Redis connection string for caching"Run pyguard validate and get clear output:
β
DATABASE_URL β present
β
SECRET_KEY β present (length: 64)
β
DEBUG β using default: false
β οΈ REDIS_URL β missing (optional, caching disabled)
All required variables are set.
$ pyguard audit
π Scanning project files...
β οΈ Potential secrets found:
config/settings.py:14
API_KEY = "sk-proj-abc123..." β hardcoded string
utils/db.py:8
password="admin123" β hardcoded credential
π Summary: 2 issues found in 2 files.
Run `pyguard audit --fix` to replace with env var references.
pyguard/
βββ pyguard/
β βββ cli.py # CLI entry point (Click)
β βββ audit.py # Secret scanning logic
β βββ validator.py # Schema validation
β βββ crypto.py # AES encryption/decryption
β βββ exporter.py # .env.example generator
β βββ scanner.py # Git history scanner
βββ tests/
βββ pyproject.toml
βββ README.md
Issues and PRs welcome. Please run tests before submitting:
pytest tests/ -vMIT Β© Robbian Saputra Gumay