Ultra-secure, high-performance .env file loader
Project description
SimpleEnvs
Ultra-secure, high-performance .env file loader for Python
Simple to use, enterprise-grade security, 2-4x faster performance
๐ Why SimpleEnvs?
Drop-in replacement for python-dotenv with proven improvements:
- ๐โโ๏ธ 2-4x faster loading performance (verified benchmarks)
- ๐ Enterprise-grade security with memory isolation
- ๐ฏ Automatic type conversion (int, bool, float)
- ๐พ Memory efficient with optimized parsing
- โก Zero configuration - works out of the box
- ๐ 100% python-dotenv compatible API
๐ Performance Benchmarks
Tested against python-dotenv (Windows 11, Python 3.11):
| Variables | File Size | python-dotenv | SimpleEnvs | Speedup |
|---|---|---|---|---|
| 10 vars | 373B | 1.40ms | 0.52ms | 2.7x faster โก |
| 100 vars | 2.3KB | 8.04ms | 2.17ms | 3.7x faster โก |
| 500 vars | 11KB | 43.1ms | 14.3ms | 3.0x faster โก |
| 1000 vars | 23KB | 102ms | 43.4ms | 2.4x faster โก |
| 5000 vars | 116KB | 1332ms | 800ms | 1.7x faster โก |
Consistent performance gains across all file sizes!
Run your own benchmarks: python -m simpleenvs.benchmark
๐ฆ Installation
pip install simpleenvs-python
โก Quick Start
Python-dotenv Migration (1-line change!)
# Before (python-dotenv)
from dotenv import load_dotenv
load_dotenv()
# After (SimpleEnvs) - Only change the import!
from simpleenvs import load_dotenv
load_dotenv() # Same API, 2-4x faster! ๐
Basic Usage
# Create .env file
echo "APP_NAME=MyApp\nDEBUG=true\nPORT=8080" > .env
# Load environment variables
from simpleenvs import load_dotenv
load_dotenv()
# Access variables
import os
print(os.getenv('APP_NAME')) # "MyApp"
print(os.getenv('DEBUG')) # "True" (auto-converted!)
print(os.getenv('PORT')) # "8080"
Type-Safe Access
import simpleenvs
simpleenvs.load_dotenv()
# Type-safe getters
app_name = simpleenvs.get_str('APP_NAME', 'DefaultApp') # str
debug = simpleenvs.get_bool('DEBUG', False) # bool
port = simpleenvs.get_int('PORT', 8080) # int
๐ Security Features
Simple Mode (Default)
Perfect for development and most production use cases:
from simpleenvs import load_dotenv
load_dotenv() # Variables stored in os.environ
Secure Mode (Enterprise)
Memory-isolated environment variables that never touch os.environ:
from simpleenvs import load_dotenv_secure, get_secure
load_dotenv_secure() # Memory-isolated loading
# Secure access (not in os.environ!)
jwt_secret = get_secure('JWT_SECRET')
db_password = get_secure('DB_PASSWORD')
# Verify isolation
import os
print(os.getenv('JWT_SECRET')) # None - properly isolated! ๐
๐ Smart Directory Scanning
Unlike python-dotenv, SimpleEnvs automatically finds your .env files!
# Your project structure
my-project/
โโโ app.py # Run from here
โโโ config/
โ โโโ .env # โ
Found automatically!
โโโ environments/
โ โโโ .env.development # โ
Found automatically!
โ โโโ .env.production # โ
Found automatically!
โโโ docker/
โโโ .env.docker # โ
Found automatically!
# python-dotenv (manual paths ๐ค)
from dotenv import load_dotenv
load_dotenv('config/.env') # Must specify each path
load_dotenv('environments/.env.development') # Must specify each path
load_dotenv('docker/.env.docker') # Must specify each path
# SimpleEnvs (auto-discovery ๐)
from simpleenvs import load_dotenv
load_dotenv() # Finds the first .env file automatically!
Smart Search Priority
SimpleEnvs searches in this order:
.env(current directory).env.local.env.development.env.production.env.stagingconfig/.env(subdirectories)environments/.env.*
# ๐ค Auto-discovery (Zero Config)
load_dotenv() # Finds first .env automatically
# ๐ฏ Manual paths (Precise Control)
load_dotenv('.env.production') # Specific file
load_dotenv('config/database.env') # Custom path
load_dotenv('/absolute/path/.env') # Absolute path
# ๐ง Advanced control
simpleenvs.load(max_depth=3) # Search 3 levels deep
simpleenvs.load(max_depth=1) # Current directory only
simpleenvs.load('custom.env', max_depth=0) # Exact file, no search
Perfect for:
- ๐ณ Docker projects with config folders
- ๐๏ธ Monorepos with nested services
- ๐ Organized projects with config directories
- ๐ง CI/CD pipelines with environment-specific configs
- ๐ฏ Custom setups with precise file control
๐ฏ Advanced Features
Async Support
import simpleenvs
# Async loading
await simpleenvs.load('.env')
await simpleenvs.load_secure('.env')
# Or async one-liner
from simpleenvs import aload_dotenv
await aload_dotenv()
FastAPI Integration
from fastapi import FastAPI
import simpleenvs
app = FastAPI()
@app.on_event("startup")
async def startup():
# Non-sensitive config
await simpleenvs.load('config.env')
# Sensitive secrets (memory-isolated)
await simpleenvs.load_secure('secrets.env')
@app.get("/config")
def get_config():
return {
"app_name": simpleenvs.get_str("APP_NAME"),
"debug": simpleenvs.get_bool("DEBUG"),
"port": simpleenvs.get_int("PORT", 8000)
}
@app.get("/auth")
def authenticate():
# Secrets not in os.environ!
jwt_secret = simpleenvs.get_secure("JWT_SECRET")
return {"authenticated": jwt_secret is not None}
Environment-Specific Loading
import simpleenvs
# Development
simpleenvs.load_dotenv('.env.development')
# Production with security
simpleenvs.load_dotenv_secure('.env.production')
# Auto-detect environment
env = os.getenv('ENVIRONMENT', 'development')
simpleenvs.load_dotenv(f'.env.{env}')
๐ SimpleEnvs vs python-dotenv
| Feature | python-dotenv | SimpleEnvs |
|---|---|---|
| Performance | Baseline | 2-4x faster โก |
| Memory Efficiency | Baseline | Optimized parsing ๐พ |
| Type Safety | Manual casting | Automatic ๐ฏ |
| Security | Basic | Enterprise-grade ๐ |
| Memory Isolation | โ | โ Secure mode |
| Async Support | โ | โ Full support |
| Auto-discovery | โ | โ Smart scanning |
| API Compatibility | โ | โ Drop-in replacement |
Type Conversion Differences
# .env file
DEBUG=true
PORT=8080
RATE=3.14
# python-dotenv (all strings)
os.getenv('DEBUG') # "true"
os.getenv('PORT') # "8080"
os.getenv('RATE') # "3.14"
# SimpleEnvs (smart conversion)
os.getenv('DEBUG') # "True" (converted from bool)
os.getenv('PORT') # "8080" (stays string)
os.getenv('RATE') # "3.14" (stays string)
# Type-safe access (recommended)
simpleenvs.get_bool('DEBUG') # True (actual bool)
simpleenvs.get_int('PORT') # 8080 (actual int)
simpleenvs.get_float('RATE') # 3.14 (actual float)
๐ ๏ธ API Reference
Loading Functions
# Simple loading (python-dotenv compatible)
load_dotenv(path=None) # Sync
aload_dotenv(path=None) # Async
# Secure loading (memory-isolated)
load_dotenv_secure(path=None, strict=True)
# Advanced loading
simpleenvs.load(path, max_depth=2) # Async with depth control
simpleenvs.load_sync(path, max_depth=2) # Sync with depth control
simpleenvs.load_secure(path, strict=True) # Full secure loading
Type-Safe Getters
# Simple access (from os.environ)
get(key, default=None) # Any type
get_str(key, default=None) # String
get_int(key, default=None) # Integer
get_bool(key, default=None) # Boolean
# Secure access (memory-isolated)
get_secure(key, default=None) # Any type
get_str_secure(key, default=None) # String
get_int_secure(key, default=None) # Integer
get_bool_secure(key, default=None) # Boolean
Utility Functions
# Status checks
is_loaded() # Simple loader status
is_loaded_secure() # Secure loader status
# Information
get_info() # Library info
get_security_info() # Security session info
get_all_keys() # All loaded keys
# Cleanup
clear() # Clear all loaded data
Classes (Advanced)
from simpleenvs import SimpleEnvLoader, SecureEnvLoader
# Simple loader
loader = SimpleEnvLoader()
await loader.load('.env')
value = loader.get('KEY')
# Secure loader
secure = SecureEnvLoader()
await secure.load_secure()
value = secure.get_secure('KEY')
๐๏ธ Use Cases
Development
# Quick setup for development
from simpleenvs import load_dotenv
load_dotenv() # Fast, simple, effective
Production Web Apps
# Public config + secure secrets
await simpleenvs.load('config.env') # Public settings
await simpleenvs.load_secure('secrets.env') # Sensitive data
Enterprise Applications
# Maximum security with monitoring
from simpleenvs import SecureEnvLoader
loader = SecureEnvLoader(session_id="prod-001")
await loader.load_secure()
# Access with logging
secret = loader.get_secure('API_KEY')
# Audit trail
logs = loader.get_access_log()
integrity_ok = loader.verify_file_integrity('.env')
Microservices
# Environment-aware loading
import os
from simpleenvs import load_dotenv_secure
env = os.getenv('ENVIRONMENT', 'development')
load_dotenv_secure(f'.env.{env}')
# Service configuration
service_name = simpleenvs.get_secure('SERVICE_NAME')
database_url = simpleenvs.get_secure('DATABASE_URL')
๐ง Configuration
Environment Detection
SimpleEnvs automatically detects your environment:
# Automatic environment-specific settings
ENVIRONMENT=production # Strict validation, minimal logging
ENVIRONMENT=development # Relaxed validation, detailed errors
ENVIRONMENT=testing # Strict validation, detailed errors
Custom Configuration
from simpleenvs.secure import LoadOptions
# Custom secure loading
options = LoadOptions(
path='.env.production',
max_depth=1,
strict_validation=True
)
await simpleenvs.load_secure(options)
๐งช Testing
Run Tests
# Install with test dependencies
pip install simpleenvs[test]
# Run full test suite
pytest tests/ -v
# Run with coverage
pytest tests/ --cov=simpleenvs --cov-report=html
Benchmarks
# Performance comparison with python-dotenv
python -m simpleenvs.benchmark
# Quick benchmark
python benchmark.py --quick
# Specific size test
python benchmark.py --size 1000
๐ Real-World Performance
SimpleEnvs shines in practical scenarios:
Web Application Startup:
- Small config (20 vars): 1.5ms โ 0.4ms (3.8x faster)
- Medium config (100 vars): 8ms โ 2ms (4x faster)
- Large config (500+ vars): 40ms โ 14ms (3x faster)
Microservice Initialization:
- Multiple .env files: Async batch loading
- Memory footprint: Optimized parsing
- Cold start time: Consistently faster
Enterprise Security:
- Sensitive data: Memory-isolated
- Audit trails: Built-in logging
- File integrity: SHA-256 verification
๐ค Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
Development Setup
# Clone repository
git clone https://github.com/simpleenvs/simpleenvs.git
cd simpleenvs
# Install in development mode
pip install -e ".[dev]"
# Run tests
pytest tests/ -v
# Format code
black src/ tests/
isort src/ tests/
๐ License
MIT License - see LICENSE file for details.
๐ Acknowledgments
- Inspired by python-dotenv
- Built with security principles from OWASP
- Performance optimizations inspired by Zig design philosophy
- Project orignated from Zig SimpleEnvs SimpleEnvs
๐ Learn More
- ๐ Full Documentation
- ๐ Issue Tracker
- ๐ฌ Discussions
- ๐ฆ PyPI Package
Made with โค๏ธ for the Python community
Simple to use, enterprise-grade security, proven performance ๐
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 simpleenvs_python-1.1.2.tar.gz.
File metadata
- Download URL: simpleenvs_python-1.1.2.tar.gz
- Upload date:
- Size: 37.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e18e98d70f9ddc36e652c8ca8e6b69b14e93f9c491cb4623229ca8d45ccc3f49
|
|
| MD5 |
ae81a25a7f1b38a670795ea673060c3a
|
|
| BLAKE2b-256 |
bc4e2b12815b3ab023b90ac429e1db55e1c8fbdff3824e8d322e88ef43e5de00
|
File details
Details for the file simpleenvs_python-1.1.2-py3-none-any.whl.
File metadata
- Download URL: simpleenvs_python-1.1.2-py3-none-any.whl
- Upload date:
- Size: 29.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
122c9f4da94de724650837487b558735bb4af277a090a17fa3ac18c4720b1195
|
|
| MD5 |
02fa045d09a374ec32adaaa25e9167dc
|
|
| BLAKE2b-256 |
1fcb3cf6c5d964134daa9ab06ed82711b21a2f66dbadf4d5f50616f0cc1b36fb
|