Simple and type-safe environment variables management for Python
Project description
easy-dotenv
Simple and type-safe environment variables management for Python.
Installation
pip install easy-dotenv
Usage
Create an environment configuration file (e.g., env_loader.py):
from easy_dotenv import EnvConfig
class Env(EnvConfig):
port: int
api_key: str
debug: bool = False # Optional with default value
workers: int = 4 # Optional with default value
env = Env()
__all__ = ['env']
Then use it in your code:
from env_loader import env
print(f"Port: {env.port}")
print(f"API Key: {env.api_key}")
print(f"Debug mode: {env.debug}") # False if not set
print(f"Workers: {env.workers}") # 4 if not set
Features
- Type validation
- Required/optional variables
- Default values
- .env file support
- Clean and simple API
- Full type hints support
- No code duplication
Error Handling
The environment validation happens when you initialize the configuration:
from easy_dotenv import EnvConfig, EnvMissingError, EnvTypeError
try:
class Env(EnvConfig):
api_key: str
port: int
env = Env()
except EnvMissingError as e:
print("Missing environment variables:", e)
except EnvTypeError as e:
print("Invalid environment variable type:", e)
Development
Setup
# Create virtual environment
python3 -m venv venv
# Activate virtual environment
source venv/bin/activate # Linux/MacOS
# or
# venv\Scripts\activate # Windows
# Install with development dependencies
pip install -e ".[dev]"
Running Tests
# Run tests
pytest
# Run tests with coverage
pytest --cov=easy_dotenv
License
MIT
Requirements
- Python 3.7 or higher
- python-dotenv>=0.19.0
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
easy_dotenv-0.2.0.tar.gz
(5.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 easy_dotenv-0.2.0.tar.gz.
File metadata
- Download URL: easy_dotenv-0.2.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4f26088f43b7d22b2108acdb62863c647eb8f3d95e3336538764eba5fa2acbf
|
|
| MD5 |
85125c541006c8a8116cfff1e10c1481
|
|
| BLAKE2b-256 |
1cb854b5993b65f853384f31cd58cbad92b5e73a1d12b8404b67f0b2e85915ff
|
File details
Details for the file easy_dotenv-0.2.0-py3-none-any.whl.
File metadata
- Download URL: easy_dotenv-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f26f42baad307c12dbaf73e19f12cfcdbef06cf15b1e71ffd798becc2fdc931
|
|
| MD5 |
a7f87ba0ce3cfb79df024555a779859a
|
|
| BLAKE2b-256 |
730bd9fecccc50b65a5dffca53e246677147a8f0dcb9d283e8fa2a2e5294f6f5
|