Python Frameworks¶
Status: 🟢 Active | Owner: Python Guild
Web Frameworks¶
FastAPI (Preferred for APIs)¶
FastAPI is the standard for all new Python REST APIs.
from fastapi import FastAPI, HTTPException, Depends
from pydantic import BaseModel
app = FastAPI(title="Order Service", version="1.0.0")
class CreateOrderRequest(BaseModel):
customer_id: str
items: list[OrderItem]
@app.post("/orders", response_model=OrderResponse, status_code=201)
async def create_order(
request: CreateOrderRequest,
service: OrderService = Depends(get_order_service),
) -> OrderResponse:
order = await service.create(request)
return OrderResponse.from_domain(order)
Required FastAPI configuration: - Enable lifespan for startup/shutdown hooks (replaces deprecated @app.on_event). - Always set title, version, and description in the FastAPI() constructor. - Mount /metrics for Prometheus and /health for liveness/readiness probes.
Django (Full-Stack / Admin)¶
Use Django when you need an admin interface, ORM-heavy CRUD application, or traditional server-rendered HTML. Django REST Framework (DRF) is approved for Django-based APIs.
# settings.py minimum required apps
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"rest_framework",
"corsheaders",
"health_check",
]
Approved Libraries by Category¶
Validation¶
| Library | Status | Notes |
|---|---|---|
| Pydantic v2 | ✅ Required | All API schemas, config models |
| marshmallow | ⚠️ Legacy | Existing services only |
| cerberus | ❌ Not approved | Do not introduce |
HTTP Clients¶
| Library | Status | Notes |
|---|---|---|
httpx | ✅ Preferred | Async and sync support |
requests | ✅ Approved | Sync-only; acceptable for scripts |
aiohttp | ⚠️ Evaluate | Existing services only |
Database¶
| Library | Status | Notes |
|---|---|---|
| SQLAlchemy 2.x | ✅ Preferred | Full ORM + core SQL |
asyncpg | ✅ Approved | Async PostgreSQL |
| Django ORM | ✅ Approved | Django-only |
psycopg3 | ✅ Approved | Direct psycopg driver |
Task Queues¶
| Library | Status | Notes |
|---|---|---|
| Celery + Redis | ✅ Approved | Background jobs |
| ARQ | ✅ Approved | Async-native alternative to Celery |
| RQ | ⚠️ Evaluate | Simple use cases only |
References¶
Last reviewed: 2025-Q4 | Owner: Python Guild