Skip to main content

A comprehensive, secure and advanced library for managing .env files

Project description

Envella Logo

Envella

A comprehensive, secure, and highly advanced environment variable management library for Python

License: GPL-3.0 PyPI Version Python Versions PyPI Downloads

Key FeaturesInstallationQuick StartAdvanced UsageSecurity FeaturesAPI ReferenceContributingLicense


🌟 Key Features

  • Enhanced Security: Robust encryption for sensitive values, protection against timing attacks, and more
  • Multi-Environment Support: Easily manage configurations across development, testing, staging, and production
  • Rich Validation: Advanced schema validation for type checking and value constraints
  • Advanced Encryption: Support for quantum-resistant hybrid encryption
  • Extensive Utilities: Comprehensive set of utility functions for security auditing and key management
  • Intuitive API: Simple yet powerful interface for managing environment variables
  • Comprehensive Documentation: Generate documentation in various formats (Markdown, HTML, JSON)
  • Intelligent Default Values: Smart handling of missing values with sensible defaults
  • MFA Support: Multi-factor authentication capabilities for enhanced security
  • Compliance Checking: Verify environment variable compliance with best practices
Envella Flow Diagram

📦 Installation

Using pip

pip install Envella

Advanced installation with optional dependencies

# Install with advanced security features
pip install Envella[advanced]

# Install with development tools
pip install Envella[dev]

# Install with testing tools
pip install Envella[test]

🚀 Quick Start

from Envella import Envella

# Create a new Envella instance
env = Envella()

# Load environment variables from .env file
env.import_env(".env")

# Access values with optional type casting
debug_mode = env.get("DEBUG", cast_type=bool)
port = env.get("PORT", default=3000, cast_type=int)
api_url = env.get("API_URL")

# Use the values in your application
if debug_mode:
    print(f"Server running in debug mode on port {port}")
    print(f"API URL: {api_url}")

Sample .env file

# Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_NAME=myapp
DB_USER=app_user
DB_PASSWORD=secure_password

# Application Settings
DEBUG=true
LOG_LEVEL=info
PORT=8000
API_URL=https://api.example.com

🔍 Advanced Usage

Encryption for Sensitive Values

from Envella import Envella, generate_secure_key

# Generate a secure encryption key
encryption_key = generate_secure_key()

# Create a Envella instance with encryption support
env = Envella(encryption_key=encryption_key)

# Load environment variables
env.import_env(".env")

# Encrypt all sensitive values
env.encrypt_sensitive_values()

# Save the encrypted environment
env.save(".env.encrypted")

# Values like DB_PASSWORD will be stored as ENC:encrypted_data

Multi-Environment Configuration

from Envella import Envella

# Create environment-specific instances
dev_env = Envella(environment="development")
prod_env = Envella(environment="production")

# Load environment-specific configuration
dev_env.import_env(".env.development")
prod_env.import_env(".env.production")

# Use the appropriate environment based on deployment
current_env = prod_env if os.environ.get("ENVIRONMENT") == "production" else dev_env

# Access environment variables
debug = current_env.get("DEBUG", cast_type=bool)

Schema Validation

from Envella import Envella

env = Envella()
env.import_env(".env")

# Define a schema for validation
schema = {
    "PORT": {
        "type": int,
        "required": True,
        "min": 1024,
        "max": 65535,
        "description": "Port to run the server on"
    },
    "LOG_LEVEL": {
        "type": str,
        "enum": ["debug", "info", "warning", "error", "critical"],
        "description": "Logging level for the application"
    },
    "API_URL": {
        "type": str,
        "pattern": r"^https://.*",
        "required": True,
        "description": "API endpoint URL (must use HTTPS)"
    }
}

# Validate against the schema
valid, errors = env.validate_against_schema(schema)

if not valid:
    for error in errors:
        print(f"Validation error: {error['message']}")
Envella Security Features

🔒 Security Features

Audit Environment Security

from Envella import Envella

env = Envella()
env.import_env(".env.production")

# Perform a comprehensive security audit
audit = env.audit_security()

# Check audit results
if not audit["compliance"]["compliant"]:
    print("Security issues found:")
    for issue in audit["security_issues"]:
        print(f"- {issue['severity'].upper()}: {issue['recommendation']}")

Quantum-Resistant Encryption

from Envella.utils import encrypt_with_quantum_resistant_hybrid, decrypt_with_quantum_resistant_hybrid

# Encrypt sensitive configuration
config_data = json.dumps({"api_keys": {"service_a": "secret_key_123"}})
encrypted = encrypt_with_quantum_resistant_hybrid(config_data, "master-password")

# Later, decrypt the configuration
decrypted = decrypt_with_quantum_resistant_hybrid(encrypted, "master-password")
config = json.loads(decrypted)

MFA Support

from Envella import Envella
from Envella.utils import generate_mfa_secret, verify_totp_code

# Generate a secret for MFA
mfa_secret = generate_mfa_secret()
print(f"Secret: {mfa_secret}")

# Verify a TOTP code
code = "123456"  # Code from authenticator app
is_valid = verify_totp_code(code, mfa_secret)

📚 API Reference

Main Class

Method Description
Envella(encryption_key=None, environment="development", user_config=None) Initialize a new Envella instance
import_env(path=".env", override=False, export_globals=False, safe_mode=True) Import environment variables from a file
get(key, default=None, cast_type=None) Get a value with optional default and type casting
set(key, value, comment=None) Set a value for a key
as_dict(cast_types=False) Return environment variables as a dictionary
keys() Return list of all environment variable keys
save(path=None, include_comments=True) Save environment variables to a file

Security Methods

Method Description
encrypt_sensitive_values() Encrypt all sensitive values
decrypt_sensitive_values() Decrypt all encrypted sensitive values
audit_security() Perform comprehensive security audit
rotate_encryption_key(new_key, rotation_window=0) Rotate the encryption key
enforce_security_policies(policies) Enforce security policies

Utility Functions

Function Description
generate_secure_key() Generate a secure encryption key
encrypt_value(value, key) Encrypt a value using a key
decrypt_value(encrypted, key) Decrypt a value using a key
cast_value(value) Cast a string value to appropriate type
generate_mfa_secret() Generate a secret for MFA
verify_totp_code(code, secret) Verify a TOTP code

🤝 Contributing

Contributions to Envella are welcome! Here's how you can contribute:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Please read CONTRIBUTING.md for more details.

📝 License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.


Made with ❤️ by Mohammad Hosseini

GitHubPyPI

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

envella-1.0.0.tar.gz (51.5 kB view details)

Uploaded Source

Built Distribution

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

envella-1.0.0-py3-none-any.whl (49.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for envella-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c020c262fbd275b735e89a244a4943e73837d5054cc5feafd3932c00a4077af4
MD5 327c43729bc407bb7b9648415578dc8b
BLAKE2b-256 8010d5e8223a6c6f5afffde7319c2014b37a7268a6e003e5eee5de70075e9d30

See more details on using hashes here.

File details

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

File metadata

  • Download URL: envella-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 49.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for envella-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9706a89d7b57b071b5f048f26eb85c05d0bd77d86a549b6aad5b728e08ebe56d
MD5 b8dcbfb52919bbaeb6b7313977a15036
BLAKE2b-256 3f0f75f469b859a046ff0d07e4c510bb8d129075020f23762a29ee6a2bde24d3

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