Skip to main content

Ultra-secure, high-performance .env file loader

Project description

SimpleEnvs

PyPI version Python License Tests

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:

  1. .env (current directory)
  2. .env.local
  3. .env.development
  4. .env.production
  5. .env.staging
  6. config/.env (subdirectories)
  7. 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

๐Ÿ“š Learn More


Made with โค๏ธ for the Python community

Simple to use, enterprise-grade security, proven performance ๐Ÿš€

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simpleenvs_python-1.0.4.tar.gz (38.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simpleenvs_python-1.0.4-py3-none-any.whl (29.3 kB view details)

Uploaded Python 3

File details

Details for the file simpleenvs_python-1.0.4.tar.gz.

File metadata

  • Download URL: simpleenvs_python-1.0.4.tar.gz
  • Upload date:
  • Size: 38.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for simpleenvs_python-1.0.4.tar.gz
Algorithm Hash digest
SHA256 87a9137c93b3e4d5bceee5a357a432d7f06a6fa3359d9d87082beb14d299d4b4
MD5 b6cb37fad27c3c157d37730ebe93ea14
BLAKE2b-256 f60eda0958166bd0d4bf4a6fb183302daf166c6a49c303a4707253b7a124a9a5

See more details on using hashes here.

File details

Details for the file simpleenvs_python-1.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for simpleenvs_python-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 779980a9d9307491636a8c598ad199914a95c681ca01aaea1010b2f00ab1ea50
MD5 86b74dd9438ff2c7a633ecedb4cd3e4e
BLAKE2b-256 e2e7d9a59ec0a5ea2ce918f1f3ecae9c79ee81877e32149a181200f1e25e885f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page