A lightweight Python package for managing environment variables with advanced features.
Project description
envplus
envplus is a lightweight, robust, and developer-friendly Python package designed to simplify environment variable management. It goes beyond basic .env loading by providing built-in type casting, automatic validation, hot reloading, and alias support—all in a single, easy-to-use interface.
🚀 Why envplus?
Managing environment variables in Python often involves repetitive boilerplate code:
- Manually casting strings to integers or booleans.
- checking if a variable exists and raising custom errors.
- Restarting the application every time a
.envvalue changes during development. - Handling legacy variable names (aliases) when migrating configurations.
envplus solves these problems by providing a centralized Env handler that takes care of the heavy lifting, allowing you to focus on building your application. It is designed to work seamlessly with Flask, Django, FastAPI, scripts, and microservices.
✨ Features
- Type Casting: Effortlessly cast environment variables to
str,int,float,bool,list, andjson. - Auto Validation: Automatically detect missing keys and invalid types with clear, readable error messages.
- Hot Reload: (Development Friendly) Automatically reload values when the
.envfile changes without restarting your app. - Alias Support: Define multiple keys for a single value (e.g.,
DATABASE_URLorDB_URL) to support legacy configs. - Strict Mode: Enforce the presence of critical environment variables, raising errors immediately if they are missing.
- Default Values: Safe and predictable handling of default values when variables are absent.
- Debug Console: A built-in helper to inspect loaded variables (sanitized for security).
- System Priority: Always prioritizes system environment variables over
.envfile values.
📦 Installation
Install envplus via pip:
pip install envplus
🛠 Usage
1. Basic Setup
Create a .env file in your project root:
APP_ENV=development
DEBUG=true
PORT=8080
ALLOWED_HOSTS=localhost,127.0.0.1
DB_CONFIG={"host": "localhost", "port": 5432}
API_KEY=
Initialize envplus in your application:
from envplus import Env
# Load environment variables
env = Env()
2. Reading Variables with Type Casting
Stop doing int(os.getenv("PORT", 8000)). Use envplus methods instead:
# String (default behavior)
app_env = env.str("APP_ENV", default="production")
# Boolean (handles 'true', '1', 'yes', 'on', etc.)
debug_mode = env.bool("DEBUG", default=False)
# Integer
port = env.int("PORT", default=3000)
# Float
threshold = env.float("THRESHOLD", default=0.5)
# List (auto-splits by comma or custom delimiter)
hosts = env.list("ALLOWED_HOSTS")
# Result: ['localhost', '127.0.0.1']
# JSON (parses JSON strings into Python objects)
db_config = env.json("DB_CONFIG")
# Result: {'host': 'localhost', 'port': 5432}
3. Strict Mode & Validation
Ensure your application doesn't start with missing configuration.
# Enable strict mode
env = Env(strict=True)
# This will raise a MissingEnvError if "SECRET_KEY" is not found
secret = env.str("SECRET_KEY")
# This is still safe because a default is provided
optional_val = env.str("OPTIONAL_KEY", default="fallback")
4. Alias Support
Great for migrations or supporting multiple naming conventions.
# Tries 'DATABASE_URL' first. If missing, tries 'DB_CONNECTION_STRING'.
db_url = env.alias(["DATABASE_URL", "DB_CONNECTION_STRING"])
5. Hot Reloading
Perfect for local development. If you change your .env file while the app is running, envplus will pick up the new value on the next access.
# ... modify .env file ...
print(env.str("MY_VAR")) # Returns the updated value!
6. Debugging
Print a summary of all loaded environment variables to the console.
env.debug()
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📄 License
This project is licensed under the MIT License.
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
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 envplusai-0.0.3.tar.gz.
File metadata
- Download URL: envplusai-0.0.3.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16bd856d84d7e9bc6548d3f64b227472fdf08db214e9a4ce63f4c7e19ba10506
|
|
| MD5 |
0fcf46a48117cde69cc8e46d99542d5f
|
|
| BLAKE2b-256 |
b41912152ce45f0b34f530be264e4e1a614e00408b3e8e215bf7165422e54a93
|
File details
Details for the file envplusai-0.0.3-py3-none-any.whl.
File metadata
- Download URL: envplusai-0.0.3-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34c9ecbfa741dc74bea3f8cd603716fcd020a834c4d990094db610766f0fe0f0
|
|
| MD5 |
eb9073faf830329c8cf147f387d86b6e
|
|
| BLAKE2b-256 |
e3e392e3a179dbd6a6fb8b4af03e22cbd273d8c42395bc00dcc37a30b675e1ed
|