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-0.1.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-0.1.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pydefinition-0.1.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-0.1.0.tar.gz
Algorithm Hash digest
SHA256 16fbcc9d1847030fbb1221f5167d581679ce569e96e228a850dded179166cc40
MD5 a02c03231a0f92342e93a72a50590efc
BLAKE2b-256 d00310cfa04f08617740df9b17cd59c9b0028ca79feedce965d2a87f9fcd0ac6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pydefinition-0.1.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-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bd15b65735dd875657526aac9a14787bbcdc8e064d90de0e8cdd336c9f12c07e
MD5 d5a24dae3dd02c0f10eff9eaf54d42a2
BLAKE2b-256 21ad4dbf149f8fccf4b26021e5f723166ba384ed8e37de499b97b0529cde81b6

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