A Python library for simplified environment variable management
Project description
EnvBider
A Python library for simplified environment variable management with type conversion and nested configuration support.
Features
- Simple environment variable access with type conversion
- Nested configuration support
- Automatic environment file (.env) loading
- Validation and default values
Installation
pip install EnvBider
Basic Usage
import envbider
# Load environment variables from .env file
envbider.load_dotenv()
# Get environment variable with type conversion
port = envbider.get('PORT', default=8000, type=int)
debug = envbider.get('DEBUG', default=False, type=bool)
# Nested configuration
config = envbider.get_nested('APP_CONFIG')
print(config['database']['host'])
Advanced Usage
Type Conversion
# Automatic type conversion
value = envbider.get('SOME_NUMBER', type=float)
Nested Configuration
# JSON string in environment variable
config = envbider.get_nested('APP_CONFIG')
# Access nested values
print(config['logging']['level'])
Custom Prefixes
from envbider.core import env_binder
# Define nested configuration classes with custom prefixes
@env_binder(prefix="DB")
class DatabaseConfig:
host: str
port: int = 5432
username: str
password: str
@env_binder
class AppConfig:
app_name: str
database: DatabaseConfig = None
# Environment variables would be:
# APP_NAME=MyApp
# DB_HOST=localhost
# DB_PORT=5432
# DB_USERNAME=admin
# DB_PASSWORD=secret
Validation
# Validate required variables
envbider.validate_required(['DB_HOST', 'DB_PORT'])
Demonstration
- Create a
.envfile:
PORT=8080
DEBUG=true
APP_CONFIG={"database": {"host": "localhost", "port": 5432}, "logging": {"level": "info"}}
- Run the example:
import envbider
envbider.load_dotenv()
port = envbider.get('PORT', type=int)
debug = envbider.get('DEBUG', type=bool)
config = envbider.get_nested('APP_CONFIG')
print(f"Port: {port}")
print(f"Debug mode: {debug}")
print(f"Database host: {config['database']['host']}")
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
envbider-0.1.0a1.tar.gz
(7.5 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 envbider-0.1.0a1.tar.gz.
File metadata
- Download URL: envbider-0.1.0a1.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81bbfdbde61e44a438729b16118e122a6ad4fab4cddf680d42bbcc86496c1889
|
|
| MD5 |
eff73f39d0daea34c3bf63621e8963c2
|
|
| BLAKE2b-256 |
accac0a771fb864abb2ecab337bcff838a46b73f4440e475ba870ea456899556
|
File details
Details for the file envbider-0.1.0a1-py3-none-any.whl.
File metadata
- Download URL: envbider-0.1.0a1-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8f6fdbdcdd41db54051c03fbded8f2314b488659808597423a5a6c90a616245
|
|
| MD5 |
bc3db995bb4c39e3ea328a3480231d6e
|
|
| BLAKE2b-256 |
8b65d77dbf069db53e63176a1d704cf5029895da78b30598805f0c3ce5752b31
|