Skip to main content

Generic web app infrastructure: PostgreSQL pooling, structured logging, rate limiting, FastAPI middleware, auth service, gateway proxy

Project description

app-platform

Generic web app infrastructure for PostgreSQL pooling, structured logging, auth, middleware, and gateway proxying.

Installation

pip install app-platform
pip install "app-platform[all]"
pip install "app-platform[fastapi]"
pip install "app-platform[auth-google]"
pip install "app-platform[gateway]"

Included subpackages

Subpackage Provides
db PostgreSQL connection pooling, pooled session helpers, migrations, and database exception utilities
logging Structured file and JSONL logging, context helpers, logger access, and decorators for timing/error instrumentation
middleware FastAPI middleware configuration for rate limiting, sessions, CORS, and validation/error handling
auth Pluggable auth service base with in-memory and PostgreSQL-backed user/session stores
gateway FastAPI router factory for proxying chat and tool approval requests to an upstream gateway

Quick usage

Database

import os

from app_platform.db import PoolManager, get_db_session

os.environ["DATABASE_URL"] = "postgresql://postgres:postgres@localhost:5432/app"

pool_manager = PoolManager(min_connections=2, max_connections=10)
pool_manager.get_pool()

with get_db_session() as conn:
    with conn.cursor() as cursor:
        cursor.execute("SELECT 1 AS ok")
        print(cursor.fetchone())

pool_manager.close()

Logging

from app_platform.logging import (
    LoggingManager,
    configure_logging,
    log_errors,
    log_operation,
    log_timing,
)

logging_manager: LoggingManager = configure_logging(app_name="orders", log_dir="./logs")
logger = logging_manager.get_logger("service")

@log_errors()
@log_timing(threshold_s=0.25)
@log_operation("create_order")
def create_order(order_id: str) -> None:
    logger.info("creating order %s", order_id)


create_order("ord_123")

Auth

from app_platform.auth import AuthServiceBase, InMemorySessionStore, InMemoryUserStore

users = {}
sessions = {}

auth = AuthServiceBase(
    session_store=InMemorySessionStore(users_dict=users, sessions_dict=sessions),
    user_store=InMemoryUserStore(users_dict=users),
)

session_id = auth.create_user_session(
    {
        "google_user_id": "user-123",
        "email": "user@example.com",
        "name": "Example User",
    }
)

print(auth.get_user_by_session(session_id))

Gateway

from fastapi import FastAPI

from app_platform.gateway import GatewayConfig, create_gateway_router

app = FastAPI()


def get_current_user():
    return {"user_id": "user-123", "email": "user@example.com"}


gateway_router = create_gateway_router(
    GatewayConfig(
        gateway_url="https://gateway.example.com",
        api_key="gateway-api-key",
        channel="web",
    ),
    get_current_user=get_current_user,
)

app.include_router(gateway_router, prefix="/gateway")

Requirements

Python 3.11+

License

MIT

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

app_platform-0.8.0.tar.gz (54.6 kB view details)

Uploaded Source

Built Distribution

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

app_platform-0.8.0-py3-none-any.whl (43.3 kB view details)

Uploaded Python 3

File details

Details for the file app_platform-0.8.0.tar.gz.

File metadata

  • Download URL: app_platform-0.8.0.tar.gz
  • Upload date:
  • Size: 54.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for app_platform-0.8.0.tar.gz
Algorithm Hash digest
SHA256 85dc4e56175fc26992fb822e72f6fc594bdabf4637b26b9460da6bdc0b2c6377
MD5 fcf78dd4f6b412f226c07281fd0bd92b
BLAKE2b-256 436dd4fe974563cec9f6c1a1143912d799e299c6ec9c0dcbde4bce65835c02fc

See more details on using hashes here.

File details

Details for the file app_platform-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: app_platform-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 43.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for app_platform-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 763b4f8262a644f8246d1fd0bf57501646a9d20bb4e2544d63fb8461eb8b9f35
MD5 3e2cdcf75629e9c7be3d3352af6fbd30
BLAKE2b-256 aa42ac2b1d568ab7234ce77bf26b6a32b498a13fc4735dc7add8d736389f7564

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