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

๐Ÿš€ Why SimpleEnvs?

Drop-in replacement for python-dotenv with game-changing improvements:

  • ๐Ÿƒโ€โ™‚๏ธ 15x faster loading performance
  • ๐Ÿ’พ 90% less memory usage
  • ๐Ÿ”’ Enterprise-grade security with memory isolation
  • ๐ŸŽฏ Automatic type conversion (int, bool, float)
  • โšก Zero configuration - works out of the box
  • ๐Ÿ”„ 100% python-dotenv compatible API

๐Ÿ“ฆ 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, 15x 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

Tested against python-dotenv on Windows 11, Python 3.11:

File Size python-dotenv SimpleEnvs Speedup
Small (30 vars) 18.27ms 1.15ms 15.93x โšก
Medium (150 vars) 61.83ms 6.75ms 9.17x โšก
Large (3000 vars) 1353ms 508ms 2.66x โšก

Memory Usage: 90% less memory consumption! ๐Ÿ’พ

Run benchmarks: python -m simpleenvs.benchmark

๐ŸŽฏ 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 15x faster โšก
Memory Baseline 90% less ๐Ÿ’พ
Type Safety Manual casting Automatic ๐ŸŽฏ
Security Basic Enterprise-grade ๐Ÿ”’
Memory Isolation โŒ โœ… Secure mode
Async Support โŒ โœ… Full support
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

# Custom benchmark
python tests/benchmark.py

๐Ÿค 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 ๐Ÿš€

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.0.tar.gz (37.4 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.0-py3-none-any.whl (28.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for simpleenvs_python-1.0.0.tar.gz
Algorithm Hash digest
SHA256 185b57e2214edfb0b0ae645c78544ec510ee5cbc2ee8e02fc72c9ccc71f31240
MD5 1f20196874a40c7882eeeea60a6c3213
BLAKE2b-256 e69876fc65b84a6b26365ba9de269851055e40555cc007fc2b14eae406fe7fd5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simpleenvs_python-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 266507a81681292446a73b476d962bce0bbd11d28b614c4ca679016ea8325f0e
MD5 bbb279ca6618110f552a987889d538b9
BLAKE2b-256 c87e789009a03ad48936c2bfc6a7e0f157e145cc3697136516272a67c1d5fbd3

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