The most comprehensive, production-ready environment variable validation library for Python
The definitive solution for Python environment variable validation that developers choose because it's genuinely the best tool available.
pip install envvar-validator
envvar-validator is the most comprehensive, feature-rich environment variable validation library for Python. Built with production-ready features, security-first design, and exceptional developer experience, it's the tool that will revolutionize how you manage environment variables.
- π Advanced Security: Secret scanning, compliance validation, encryption key verification
- π Framework Integration: Seamless Django, Flask, FastAPI support
- π Monitoring & Observability: Health checks, drift detection, performance metrics
- π οΈ Developer Tools: CLI, interactive setup, codebase scanning
- ποΈ Team Collaboration: Shared templates, audit logging, change notifications
- π§ Extensible Architecture: Plugin system, custom validators, middleware support
- π± Cross-Platform: Windows, macOS, Linux support
- π― Zero Configuration: Works out of the box with sensible defaults
from env_validator import EnvironmentValidator, ValidationError
# Define your environment schema
validator = EnvironmentValidator({
"DATABASE_URL": {
"type": "str",
"required": True,
"validators": ["database_url"]
},
"API_KEY": {
"type": "str",
"required": True,
"validators": ["api_key"],
"sensitive": True
},
"DEBUG": {
"type": "bool",
"default": False
},
"PORT": {
"type": "int",
"default": 8000,
"validators": ["port_range"]
}
})
# Validate your environment
try:
config = validator.validate()
print(f"β
Environment validated successfully!")
print(f"Database: {config.DATABASE_URL}")
print(f"Debug mode: {config.DEBUG}")
except ValidationError as e:
print(f"β Environment validation failed: {e}")
# settings.py
from env_validator import DjangoEnvironmentValidator
env = DjangoEnvironmentValidator({
"SECRET_KEY": {"type": "str", "required": True, "validators": ["secret_key"]},
"DATABASE_URL": {"type": "str", "required": True, "validators": ["database_url"]},
"DEBUG": {"type": "bool", "default": False},
"ALLOWED_HOSTS": {"type": "list", "default": ["localhost"]},
})
# Validate and load environment
config = env.validate()
SECRET_KEY = config.SECRET_KEY
DATABASES = {
'default': env.parse_database_url(config.DATABASE_URL)
}
DEBUG = config.DEBUG
ALLOWED_HOSTS = config.ALLOWED_HOSTS
# config.py
from env_validator import FastAPIEnvironmentValidator
from pydantic import BaseSettings
class Settings(BaseSettings):
env_validator = FastAPIEnvironmentValidator({
"DATABASE_URL": {"type": "str", "required": True},
"API_KEY": {"type": "str", "required": True, "sensitive": True},
"ENVIRONMENT": {"type": "str", "default": "development"},
})
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.env_validator.validate()
settings = Settings()
# Validate current environment
envvar-validator validate
# Validate with custom schema file
envvar-validator validate --schema schema.yaml
# Generate environment report
envvar-validator report --output html
# Interactive environment setup wizard
envvar-validator setup
# Generate configuration templates
envvar-validator template --framework django
# Scan for secrets and sensitive data
envvar-validator scan --secrets
# Compliance check
envvar-validator scan --compliance gdpr
from env_validator import BaseValidator, ValidationError
class CustomAPIValidator(BaseValidator):
def validate(self, value: str) -> str:
if not value.startswith("api_"):
raise ValidationError("API key must start with 'api_'")
return value
validator = EnvironmentValidator({
"API_KEY": {
"type": "str",
"validators": [CustomAPIValidator()]
}
})
validator = EnvironmentValidator({
"DATABASE_URL": {
"type": "str",
"required": True,
"environments": {
"development": "sqlite:///dev.db",
"staging": {"type": "str", "validators": ["database_url"]},
"production": {"type": "str", "validators": ["database_url", "ssl_required"]}
}
}
})
from env_validator import MonitoringValidator
# Health check endpoint
@app.get("/health/env")
async def environment_health():
return MonitoringValidator.health_check()
# Metrics endpoint
@app.get("/metrics/env")
async def environment_metrics():
return MonitoringValidator.get_metrics()
secret_key
: Validates secret key strength and entropyapi_key
: Validates API key format and securityencryption_key
: Validates encryption key requirementspassword_strength
: Checks password complexity requirements
url
: Validates URL format and accessibilityip_address
: Validates IPv4/IPv6 addressesport_range
: Validates port numbersdatabase_url
: Validates database connection strings
email
: RFC-compliant email validationjson
: JSON format validationfile_path
: File path existence and permissionsdirectory_path
: Directory existence and permissions
aws_arn
: AWS ARN format validationgcp_project_id
: Google Cloud project ID validationazure_resource_id
: Azure resource identifier validation
validator = EnvironmentValidator({
"API_KEY": {
"type": "str",
"sensitive": True,
"validators": ["secret_scanning"]
}
})
# Automatically detects and protects sensitive values
config = validator.validate()
print(config.API_KEY) # Shows: "***REDACTED***"
validator = EnvironmentValidator({
"PII_DATA": {
"type": "str",
"compliance": ["gdpr", "hipaa"],
"encryption": "required"
}
})
from env_validator import HealthChecker
# Check environment health
health = HealthChecker.check()
if not health.is_healthy:
print(f"Environment issues: {health.issues}")
from env_validator import DriftDetector
# Detect configuration drift
drift = DriftDetector.detect()
if drift.has_changes:
print(f"Configuration drift detected: {drift.changes}")
# settings.py
from env_validator.django import DjangoEnvironmentValidator
env = DjangoEnvironmentValidator.from_settings_file()
config = env.validate()
# Automatic Django settings integration
SECRET_KEY = config.SECRET_KEY
DATABASES = config.DATABASES
# app.py
from env_validator.flask import FlaskEnvironmentValidator
app = Flask(__name__)
env = FlaskEnvironmentValidator(app, {
"SECRET_KEY": {"type": "str", "required": True},
"DATABASE_URL": {"type": "str", "required": True},
})
# main.py
from env_validator.fastapi import FastAPIEnvironmentValidator
app = FastAPI()
env = FastAPIEnvironmentValidator(app, {
"API_KEY": {"type": "str", "required": True},
"DATABASE_URL": {"type": "str", "required": True},
})
- Lazy Loading: Validators load only when needed
- Caching: Repeated validations are cached
- Async Support: Non-blocking validation operations
- Memory Efficient: Minimal memory footprint
- π Full Documentation
- π Quick Start Guide
- π§ API Reference
- ποΈ Framework Integrations
- π Security Guide
We welcome contributions! Please see our Contributing Guide for details.
git clone https://github.com/Sherin-SEF-AI/envvar-validator.git
cd envvar-validator
pip install -e ".[dev]"
pre-commit install
pytest
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with β€οΈ by the Python community
- Inspired by the need for better environment variable management
- Thanks to all contributors and users
- β Core validation engine
- β Advanced validators library
- β Framework integrations
- β CLI tools
- β Security features
- β Monitoring & observability
- β Documentation
- β Testing suite
- π§ Community features
- π§ Performance optimizations
Made with β€οΈ by Sherin Joseph Roy
GitHub | Documentation | Issues | Discussions