Skip to main content

Environment-driven configuration helpers with low boilerplate

Project description

PyDefinition

Environment-driven configuration helpers with low boilerplate.

Installation

pip install pydefinition

Features

  • Environment variable management with descriptors
  • Type casting for environment variables
  • Default values and required variables
  • Automatic naming based on class structure
  • Caching for performance

Usage

from pydefinition import EnvVar, parse_bool, parse_int, Required

class AppConfig:
    # Basic usage with default value
    PORT = EnvVar(default=8080, cast=parse_int)
    
    # Required environment variable (raises KeyError if not set)
    API_KEY = EnvVar(default=Required)
    
    # Boolean parsing
    DEBUG = EnvVar(default=False, cast=parse_bool)
    
    # Custom name for environment variable
    DATABASE_URL = EnvVar(default="sqlite:///app.db", name="DB_URL")

# Usage
config = AppConfig()
port = config.PORT  # Will read from APP_CONFIG_PORT or use default 8080
api_key = config.API_KEY  # Will read from APP_CONFIG_API_KEY or raise KeyError

Advanced Usage

See the examples directory for more advanced usage patterns.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

pydefinition-1.0.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

pydefinition-1.0.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file pydefinition-1.0.0.tar.gz.

File metadata

  • Download URL: pydefinition-1.0.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for pydefinition-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ea051bca5a316421b03c98666d9e918db6e6ca475181ff7ef0015009a8b43b4a
MD5 5314e8036fcc1a4dc05e61809b05cbc7
BLAKE2b-256 4dd35f0839c3aeeabea6119f790a691bbff68ea14e5b034c0a8ce04bdb3e309f

See more details on using hashes here.

File details

Details for the file pydefinition-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pydefinition-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for pydefinition-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b2197c94638056777045231af13257577bc60a425f0bcb6b86df59284db46f87
MD5 af8bfbea223939812cf3c0462223f52f
BLAKE2b-256 ece970a272d05370ff2f4a8fef9276779b3e431b7f5c8b4763da8e37522d3889

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