Skip to main content

Validate environment configuration at Python app startup with security-first design

Project description

pyenvcheck

PyPI Python Version License CI Status

Validate environment configuration at Python app startup with security-first design.

Python applications often fail late because configuration is not validated at startup. pyenvcheck provides a clean, secure way to:

  • ✅ Load and validate environment configuration from .env, TOML, and YAML files
  • ✅ Define required/optional keys with type coercion and defaults
  • ✅ Apply custom validators and transformations
  • ✅ Mask sensitive values in startup summaries
  • ✅ Get structured config as dataclass or Pydantic models
  • ✅ Use the CLI to check config validity before deployment
  • ✅ Integrate seamlessly with Django, FastAPI, and Flask

Quick Start

Installation

pip install pyenvcheck

Basic Usage

from pyenvcheck import Config

config = Config({
    'DATABASE_URL': {'required': True},
    'DEBUG': {'type': bool, 'default': False},
    'PORT': {'type': int, 'default': 8000},
    'SECRET_KEY': {'required': True, 'mask': True},
})

# Load from environment
validated_config = config.validate()

# Or load from .env file
validated_config = config.load_env('.env').validate()

# Access config
print(validated_config.DATABASE_URL)

# Get startup summary (secrets masked)
print(validated_config.summary())

Output as Pydantic Model

from pydantic import BaseModel
from pyenvcheck import Config

class Settings(BaseModel):
    database_url: str
    debug: bool = False
    port: int = 8000

config = Config.from_pydantic(Settings)
settings = config.load_env('.env').validate_as(Settings)

CLI Check

# Validate configuration before deploying
pyenvcheck check --config config.yaml --env production

# Generate example config
pyenvcheck generate --output .env.example

Django Integration

# settings.py
from pyenvcheck.adapters.django import get_settings

ALLOWED_HOSTS = get_settings(settings_dict).ALLOWED_HOSTS

FastAPI Integration

from pyenvcheck.adapters.fastapi import get_settings

settings = get_settings()
app = FastAPI()

Features

  • Multiple Source Support: Load config from environment variables, .env files, YAML, and TOML
  • Source Merging: Combine multiple config sources with defined priority
  • Type Coercion: Automatic conversion to int, bool, float, list, etc.
  • Validation: Required fields, optional with defaults, custom validators
  • Security: Mask sensitive values in logs and summaries
  • Structured Output: Pydantic or dataclass-style access
  • CLI Tools: Validate config and generate examples
  • Framework Integration: Django, FastAPI, Flask adapters
  • Comprehensive Errors: Clear error messages with suggestions

Documentation

Development

# Clone and install in development mode
git clone https://github.com/yourusername/pyenvcheck.git
cd pyenvcheck
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black src tests
isort src tests

# Type checking
mypy src

# Build docs
mkdocs serve

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please see our contribution 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

pyenvcheck-0.1.1.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

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

pyenvcheck-0.1.1-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file pyenvcheck-0.1.1.tar.gz.

File metadata

  • Download URL: pyenvcheck-0.1.1.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for pyenvcheck-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3aa9040511995f9a769817334ce6e895d5b857168d4965800b977bae4ca95110
MD5 d6c94e164b228f323b4a6dec47579737
BLAKE2b-256 23a2f91a219ddce9e32a2df593ebb65dcdc25b5948a524437f61c6a28aa66d11

See more details on using hashes here.

File details

Details for the file pyenvcheck-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pyenvcheck-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for pyenvcheck-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2493c904832e4b79cca9fe7bf791cc53fa02bc3a334a9af9fd607b1539c55b5b
MD5 d1315ac76ee6e58dd746819b7a0ecfa8
BLAKE2b-256 eef2c4e663b1c26eaf9ee34a8710089d9766c931fe2d170cc0168a6f984fc4d6

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