Skip to main content

Modern Python 3.11+ Framework: Flask/FastAPI orchestration, and strict runtime enforcement.

Project description

py_aide

Modern Python 3.11+ Framework: Flask/FastAPI Orchestration & Strict Runtime Enforcement

py_aide is a robust, developer-centric framework designed to bring safety, structure, and consistency to Python web applications. It provides a unique "Strict Runtime Enforcement" layer that ensures your code remains clean, documented, and type-safe at execution time.

🚀 Key Features

  • Strict Runtime Enforcement: A powerful decorator that enforces type hints, docstrings, and calling conventions (positional-only/keyword-only) at runtime.
  • Unified Server Portal: Seamlessly orchestrate Flask and FastAPI applications with shared security gates and auto-discovery of routes.
  • WebSocket Excellence: Built-in support for WebSockets (powered by Eventlet and Flask-SocketIO) with integrated security and metrics.
  • Thread-Safe SQL: A thread-level multiton SQLite manager with automatic JSON serialization, transaction tracking, and schema management.
  • Modern Security: First-class support for Bearer tokens, API keys, and Fernet-based encryption.
  • Rich Utilities: Built-in handlers for images (base64/files), dates (aware/naive conversions), and custom data structures.

📦 Installation

pip install py_aide

Note: py_aide requires Python 3.11+ and is currently optimized for Linux environments.

⚙️ Core Philosophy: Strict Enforcement

At the heart of py_aide is the @enforce_requirements decorator. It's designed to prevent "sloppy" code by failing early if:

  • A function is missing a docstring.
  • A parameter or return value is missing a type hint.
  • A function uses more than 8 arguments (promoting better decomposition).
  • Calling conventions (/ or *) are not explicitly defined.
from py_aide.enforcer import enforce_requirements

@enforce_requirements
def create_user(name: str, age: int, /) -> dict:
    """Creates a new user dict."""
    return {"name": name, "age": age}

🌐 Unified Server Example (Flask)

from py_aide.servers.flask import ServicePortal, GateConfig

portal = ServicePortal()

@portal.endpoint("/api/greet", gate=GateConfig(auth_required=False))
def greet(name: str, /) -> dict:
    """Returns a greeting message."""
    return {"message": f"Hello, {name}!"}

if __name__ == "__main__":
    portal.run(port=5000)

🗄️ Database Management

py_aide provides a thread-local multiton pattern for SQLite, ensuring each thread has its own connection while sharing the same configuration.

from py_aide.database import Api

db_config = {
    'users': 'id INTEGER PRIMARY KEY, name TEXT, meta JSON'
}

with Api(db_path="data.db", tables=db_config) as db:
    db.insert(table="users", data=[(1, "Alice", {"role": "admin"})])
    result = db.fetch(table="users", columns=["name", "meta::role as role"])
    print(result.data) # [{'name': 'Alice', 'role': 'admin'}]

⚠️ Important Note: Eventlet Monkey Patching

By default, importing src.py_aide (or the top-level package) immediately performs eventlet.monkey_patch(). This is required for reliable WebSocket support and some threading features. If you need to avoid this side-effect, ensure you understand the dependencies of your modules.

📄 License

This project is licensed under the MIT License. See the LICENSE file for more details.

👥 Authors

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

py_aide-0.10.1.tar.gz (169.9 kB view details)

Uploaded Source

Built Distribution

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

py_aide-0.10.1-py3-none-any.whl (175.5 kB view details)

Uploaded Python 3

File details

Details for the file py_aide-0.10.1.tar.gz.

File metadata

  • Download URL: py_aide-0.10.1.tar.gz
  • Upload date:
  • Size: 169.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for py_aide-0.10.1.tar.gz
Algorithm Hash digest
SHA256 c7e6bd6724210d9c5a114670508b9aca465ab98e1344aa08d2270ba24ad2e751
MD5 f5a2fd5f5453a4cf122ea035074f3cad
BLAKE2b-256 25e70188e2eca56f237f8ab2e9e904f77414eda83ec90f90f6f69605bb79ab47

See more details on using hashes here.

File details

Details for the file py_aide-0.10.1-py3-none-any.whl.

File metadata

  • Download URL: py_aide-0.10.1-py3-none-any.whl
  • Upload date:
  • Size: 175.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for py_aide-0.10.1-py3-none-any.whl
Algorithm Hash digest
SHA256 396c0da43ae7c3f739462678e31096e7bb8b2ae74f5efa1374c9043bc74bcd88
MD5 8568efd391be026f0d7aed4eb53853c8
BLAKE2b-256 99ba2b10201d37eb76259ff7720d5ed12d7a0ab85815a4e66691f4c4cc531c97

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