Skip to main content

A typed, validated, and secure environment loader for Python projects with automatic type casting, validation, secret masking, and schema support.

Project description

env-loader-pro

Enterprise-grade typed, validated, and secure environment variable loader for Python with automatic type casting, validation, secret masking, cloud secrets integration, and full observability.

🎯 What Problem Does This Solve?

Traditional .env loaders are basic and unsafe. env-loader-pro provides:

  • Type safety - Automatic casting to int, bool, list, etc.
  • Cloud secrets - Azure Key Vault, AWS Secrets Manager integration
  • Audit trail - Complete provenance tracking for compliance
  • Policy enforcement - Policy-as-code for configuration governance
  • CI/CD safe - All commands work without cloud credentials
  • Secret security - Automatic masking, never logs secrets

🚀 Key Features

  • Load from .env + system env with deterministic precedence
  • Automatic type casting (int, bool, list, JSON)
  • Required/optional validation with helpful errors
  • Default values support
  • Secret masking for safe printing/logging
  • Environment variable expansion (${VAR} syntax)
  • Multiple environment support (.env.dev, .env.prod, etc.)
  • Cloud secrets - Azure Key Vault, AWS Secrets Manager
  • Audit trail - Full provenance tracking
  • Failure policies - Per-provider error handling
  • Policy-as-code - JSON/YAML policy enforcement
  • Configuration diff - Drift detection
  • Schema support (Pydantic models & dataclasses)
  • CLI tool for common operations
  • CI/CD safe - No cloud access required

📦 Installation

pip install env-loader-pro

Optional Dependencies

# For Pydantic schema support
pip install env-loader-pro[pydantic]

# For Azure Key Vault
pip install env-loader-pro[azure]

# For AWS Secrets Manager
pip install env-loader-pro[aws]

# For YAML export
pip install env-loader-pro[yaml]

# For everything
pip install env-loader-pro[all]

🎯 Quickstart

Basic Usage

from env_loader_pro import load_env

config = load_env(
    required=["API_KEY"],
    types={"PORT": int, "DEBUG": bool},
    defaults={"PORT": 8080}
)

print(config["PORT"])  # 8080 (int)
print(config["DEBUG"])  # True (bool)

With Cloud Secrets (Azure)

from env_loader_pro import load_env
from env_loader_pro.providers import AzureKeyVaultProvider

provider = AzureKeyVaultProvider(
    vault_url="https://myvault.vault.azure.net"
)

config = load_env(
    env="prod",
    providers=[provider],
    audit=True  # Track provenance
)

# Get audit trail
config, audit = load_env(audit=True)
print(audit.to_json())

With Cloud Secrets (AWS)

from env_loader_pro import load_env
from env_loader_pro.providers import AWSSecretsManagerProvider

provider = AWSSecretsManagerProvider(
    secret_id="myapp/prod",
    region="us-east-1"
)

config = load_env(
    env="prod",
    providers=[provider],
    failure_policy={"aws": "fallback"}  # Graceful degradation
)

With Policy-as-Code

from env_loader_pro import load_env

# policy.yaml:
# require:
#   - API_KEY
#   - DB_PASSWORD
# forbid:
#   - DEBUG

config = load_env(
    env="prod",
    policy="policy.yaml"  # Enforces requirements
)

Schema Support

from env_loader_pro import load_with_schema
from pydantic import BaseModel

class Config(BaseModel):
    port: int = 8080
    debug: bool = False
    api_key: str  # Required

config = load_with_schema(Config, env="prod")
print(config.port)  # Typed access

🛠️ CLI Tool

# Show environment variables
envloader show --env prod

# Validate (CI-safe, no cloud access)
envloader validate --ci --required API_KEY PORT

# Audit trail
envloader audit --json

# Explain precedence
envloader explain

# Configuration diff
envloader diff --ci --deny-secret-changes

# Export to JSON/YAML
envloader export --output config.json --format json

# Generate .env.example
envloader generate-example --required API_KEY PORT

🔒 Security Features

  • Automatic secret masking - Keys containing secret, key, token, password, pwd are masked
  • Audit trail - Complete provenance tracking (source, provider, timestamp)
  • Policy enforcement - Require/forbid variables via policy files
  • Secret change detection - Prevent accidental exposure
  • Encrypted .env - Support for age/GPG encrypted files
  • Never logs secrets - All outputs are safe

📊 Configuration Precedence

Deterministic priority order (highest to lowest):

  1. Cloud providers (Azure Key Vault, AWS Secrets Manager)
  2. System environment variables
  3. Docker/K8s mounted secrets
  4. .env.{env} (environment-specific)
  5. Base .env file
  6. Schema defaults

See envloader explain for detailed documentation.

📚 Documentation

🧪 Testing

pip install -e ".[test]"
pytest tests/

📝 License

Apache License 2.0 - See LICENSE file for details.

🤝 Contributing

Contributions welcome! See CONTRIBUTING.md for guidelines.

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

env_loader_pro-1.0.1.tar.gz (58.5 kB view details)

Uploaded Source

Built Distribution

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

env_loader_pro-1.0.1-py3-none-any.whl (65.6 kB view details)

Uploaded Python 3

File details

Details for the file env_loader_pro-1.0.1.tar.gz.

File metadata

  • Download URL: env_loader_pro-1.0.1.tar.gz
  • Upload date:
  • Size: 58.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for env_loader_pro-1.0.1.tar.gz
Algorithm Hash digest
SHA256 80e448ce2ea8aed7d0b1a06ce64d009f03ea0c8bf5e0e59e94cb72521d6a7b0d
MD5 f9d3704b41b032ffcb1ac9451250caee
BLAKE2b-256 7b99012187ba6278d7c8d81a02b4972c6a294b543391e84d5f10efb6d9825b2f

See more details on using hashes here.

File details

Details for the file env_loader_pro-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: env_loader_pro-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 65.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for env_loader_pro-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7bce619207c4058aa236b14bc0566bf0374c1a7d98a09974c8bac1833dccf80f
MD5 e4b4c3986c96d44fd84421fe39d43191
BLAKE2b-256 4354293da68d077815770a773a2e4f0932ca817ebfba2e704e1f17c7b56ce479

See more details on using hashes here.

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