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.1.tar.gz
(4.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydefinition-1.0.1.tar.gz.
File metadata
- Download URL: pydefinition-1.0.1.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b6a71781e5deb332a9bb69e01949006b832155226d69b2d0bf46982d43ce164
|
|
| MD5 |
716fcd66c7778bb4170974d41dc82302
|
|
| BLAKE2b-256 |
de618010ef30b1d9d31bd265235496922fe6930d2cd4c161ae53e48cf594cc0f
|
File details
Details for the file pydefinition-1.0.1-py3-none-any.whl.
File metadata
- Download URL: pydefinition-1.0.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f617a7379a07a4f547517e4886fb57f07321aa0c33ffd640a4727da5d99c0a8c
|
|
| MD5 |
a1d844bf12780c75eebdeabcac216b87
|
|
| BLAKE2b-256 |
c8dddde2b9f86152353ea9081bf539b0a0d397ad35255c481d088666d7a9e453
|