Smart .env loader with validation, fallback values, and secure masking.
Project description
smartenv
Smart .env loader with validation, fallback values, and secure variable handling.
Simplify your environment variable management across any Python project with smart defaults, type conversion, required flags, and secure masking.
🚀 Features
- 📦 Load variables from a
.envfile - 🔐 Secure environment variables (masked in logs)
- ✅ Required variable enforcement
- 🧠 Smart default values with type conversion
- 📜 Simple API for any Python project (CLI, backend, scripts, etc.)
📦 Installation
pip install smartenv
⚡ Quick Usage
from smartenv import load_env, get_env, require_env, secure_env
load_env() # Loads from .env
DEBUG = get_env("DEBUG", default=False, type=bool)
PORT = get_env("PORT", default=8000, type=int)
API_KEY = require_env("API_KEY")
DB_PASS = secure_env("DB_PASS")
print("DEBUG:", DEBUG)
print("DB_PASS (safe):", DB_PASS)
📄 .env Example
DEBUG=true
PORT=5000
API_KEY=supersecretkey
DB_PASS=sensitivepassword
📛 Exceptions
| Exception | Raised When |
|---|---|
MissingEnvError |
A required or secure variable is not found |
InvalidEnvTypeError |
Type conversion fails (e.g., "abc" → int) |
🔧 Supported Types
-
str (default)
-
int
-
float
-
bool (true, 1, yes, etc.)
🛡 Secure Variables
password = secure_env("SECRET")
print(password) # prints: ******
str(password) # prints: ******
actual = password == "SECRET" # ✅ True
📚 License
MIT License © 2025 Ayomide Adediran https://github.com/Ay-developerweb/smartenv
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 smartenvx-0.1.0.tar.gz.
File metadata
- Download URL: smartenvx-0.1.0.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9552c1132ad5b64e83d828392048bf99e38725518a6ceb6272706c2514ffea83
|
|
| MD5 |
63fc74d62354c49508821b4293a9c1ec
|
|
| BLAKE2b-256 |
b94c8f95d47b321bd26c8ddab445d2f231bce3c7332c74cce703170d2f1f6bd2
|
File details
Details for the file smartenvx-0.1.0-py3-none-any.whl.
File metadata
- Download URL: smartenvx-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25a9a06b4285bd86fe083bfebcecc39ae16525da15cf90bfddc2f418c2f28706
|
|
| MD5 |
dd09314cc457f83cdd5f44715c9f213d
|
|
| BLAKE2b-256 |
a6709ba03d108c62206d6ce2cf3643e22ba946222e5b2dec0483d6ffba4d6e57
|