Skip to main content

A comprehensive Python framework for building secure medical and business applications

Project description

Essencia

A comprehensive Python framework for building secure medical and business applications with Brazilian market support.

Python 3.12+ License: MIT

Features

  • Security First: Field-level encryption, XSS protection, rate limiting, CSRF tokens
  • Medical Ready: Encrypted medical fields, LGPD compliance features
  • Brazilian Support: CPF/CNPJ validators, phone formatting, Portuguese error messages
  • Dual Database: Async (Motor) and sync (PyMongo) MongoDB support
  • Smart Caching: Redis-based intelligent caching with fallback
  • Modern UI: Built on Flet (Flutter for Python)
  • Type Safe: Full type hints and Pydantic validation

Installation

# Basic installation
pip install essencia

# With security extras (bcrypt, argon2)
pip install essencia[security]

Quick Start

Environment Setup

Create a .env file:

# Required for encryption features
ESSENCIA_ENCRYPTION_KEY="your-base64-encoded-32-byte-key"

# Database connections (optional, defaults to localhost)
MONGODB_URL="mongodb://localhost:27017"
REDIS_URL="redis://localhost:6379"

Generate an encryption key:

python -c "import secrets; import base64; print(base64.b64encode(secrets.token_bytes(32)).decode())"

Basic Usage

from essencia import MongoModel, CPFValidator, EncryptedCPF
from essencia.fields import DefaultDateTime

# Define a model with encrypted fields
class Patient(MongoModel):
    COLLECTION_NAME = "patients"
    
    name: str
    cpf: EncryptedCPF  # Automatically encrypted/decrypted
    created_at: DefaultDateTime
    
# Validate Brazilian data
try:
    CPFValidator.validate("123.456.789-09")
except ValidationError as e:
    print(f"Invalid CPF: {e}")

# Use the model
patient = Patient(name="João Silva", cpf="123.456.789-09")
patient.save_self()  # CPF is encrypted in database

Security Features

from essencia.security import sanitize_input, RateLimiter
from essencia.cache import IntelligentCache

# Input sanitization
clean_html = sanitize_input("<script>alert('xss')</script>Hello")
# Result: "Hello"

# Rate limiting
rate_limiter = RateLimiter()
if rate_limiter.is_allowed("user-123", "login"):
    # Process login
    pass

# Intelligent caching
cache = IntelligentCache()
cache.set("user:123", user_data, ttl=3600)

Service Pattern

from essencia.services import EnhancedBaseService

class PatientService(EnhancedBaseService):
    model_class = Patient
    collection_name = "patients"
    
    async def find_by_cpf(self, cpf: str):
        # CPF is automatically encrypted for search
        return await self.find_one({"cpf": cpf})

Components

Models

  • MongoModel - Base model for MongoDB with sync operations
  • BaseModel - Async base model using Motor
  • Built-in field types: MongoId, ObjectReferenceId, StrEnum

Security

  • Sanitization: HTML/Markdown sanitizers for XSS prevention
  • Session Management: Secure sessions with CSRF protection
  • Authorization: Role-based access control (RBAC)
  • Rate Limiting: Multiple strategies (sliding window, token bucket)
  • Encryption: Field-level encryption for sensitive data

Validators

  • CPFValidator - Brazilian CPF validation and formatting
  • CNPJValidator - Brazilian CNPJ validation
  • PhoneValidator - Brazilian phone numbers
  • EmailValidator - Email validation
  • MoneyValidator - Brazilian currency formatting
  • DateValidator - Date validation with business rules

Fields

  • EncryptedCPF, EncryptedRG - Encrypted Brazilian documents
  • EncryptedMedicalData - For medical records
  • DefaultDate, DefaultDateTime - Auto-populated timestamps

Documentation

Requirements

  • Python 3.12+
  • MongoDB 4.0+
  • Redis 6.0+ (optional, for caching)

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

  • Create an issue for bug reports or feature requests
  • For security issues, see SECURITY.md

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

essencia-1.6.0.tar.gz (220.1 kB view details)

Uploaded Source

Built Distribution

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

essencia-1.6.0-py3-none-any.whl (215.6 kB view details)

Uploaded Python 3

File details

Details for the file essencia-1.6.0.tar.gz.

File metadata

  • Download URL: essencia-1.6.0.tar.gz
  • Upload date:
  • Size: 220.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for essencia-1.6.0.tar.gz
Algorithm Hash digest
SHA256 9b4f606bd4b0cea9d9d0ba922e5fc382fe8f7ca0c296c1c3d52ab39b56c0b806
MD5 d57c4c97bcc2d9df5083d346738ce41b
BLAKE2b-256 2e194d207f5300e24f82ca989545fe9de13dcbcae0ce7202590e4e06794ffbff

See more details on using hashes here.

Provenance

The following attestation bundles were made for essencia-1.6.0.tar.gz:

Publisher: publish.yml on arantesdv/essencia

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file essencia-1.6.0-py3-none-any.whl.

File metadata

  • Download URL: essencia-1.6.0-py3-none-any.whl
  • Upload date:
  • Size: 215.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for essencia-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1bd786640024efa9d977f9001ac5787623c858a60c5e04795785a5be35537bf5
MD5 19a23e7b3f552d4e7d9c17a6bdcd444f
BLAKE2b-256 d6c520cea510556fceb3d0e492144b2d42149c6dc1a84075dca99d5fbc1f0beb

See more details on using hashes here.

Provenance

The following attestation bundles were made for essencia-1.6.0-py3-none-any.whl:

Publisher: publish.yml on arantesdv/essencia

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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