From ork
Provides production patterns for async Python backends using FastAPI dependencies, SQLAlchemy 2.0 async sessions, asyncio TaskGroup, and connection pooling. Use for services, endpoints, DB sessions, or pool tuning.
How this skill is triggered — by the user, by Claude, or both
Slash command
/ork:python-backendThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Patterns for building production Python backends with asyncio, FastAPI, SQLAlchemy 2.0, and connection pooling. Each category has individual rule files in `rules/` loaded on-demand.
assets/fastapi-app-template.pychecklists/async-implementation-checklist.mdchecklists/connection-pool-checklist.mdchecklists/fastapi-production-checklist.mdchecklists/sqlalchemy-async-checklist.mdexamples/asyncio-examples.mdexamples/connection-pooling-examples.mdexamples/fastapi-lifespan.mdexamples/sqlalchemy-async-examples.mdmetadata.jsonreferences/eager-loading.mdreferences/fastapi-app-boilerplate.mdreferences/fastapi-integration.mdreferences/middleware-stack.mdreferences/pool-sizing.mdreferences/semaphore-patterns.mdreferences/taskgroup-patterns.mdrules/_sections.mdrules/_template.mdrules/asyncio-cancellation.mdPatterns for building production Python backends with asyncio, FastAPI, SQLAlchemy 2.0, and connection pooling. Each category has individual rule files in rules/ loaded on-demand.
| Category | Rules | Impact | When to Use |
|---|---|---|---|
| Asyncio | 3 | HIGH | TaskGroup, structured concurrency, cancellation handling |
| FastAPI | 3 | HIGH | Dependencies, middleware, background tasks |
| SQLAlchemy | 3 | HIGH | Async sessions, relationships, migrations |
| Pooling | 3 | MEDIUM | Database pools, HTTP sessions, tuning |
Total: 12 rules across 4 categories
# FastAPI + SQLAlchemy async session
async def get_db() -> AsyncGenerator[AsyncSession, None]:
async with async_session_factory() as session:
try:
yield session
await session.commit()
except Exception:
await session.rollback()
raise
@router.get("/users/{user_id}")
async def get_user(user_id: UUID, db: AsyncSession = Depends(get_db)):
result = await db.execute(select(User).where(User.id == user_id))
return result.scalar_one_or_none()
# Asyncio TaskGroup with timeout
async def fetch_all(urls: list[str]) -> list[dict]:
async with asyncio.timeout(30):
async with asyncio.TaskGroup() as tg:
tasks = [tg.create_task(fetch_url(url)) for url in urls]
return [t.result() for t in tasks]
Modern Python asyncio patterns using structured concurrency, TaskGroup, and Python 3.11+ features.
gather() with structured concurrency and auto-cancellationasyncio.timeout() context manager for composable timeoutsexcept* with ExceptionGroup for handling multiple task failuresasyncio.to_thread() for bridging sync code to async| Decision | Recommendation |
|---|---|
| Task spawning | TaskGroup not gather() |
| Timeouts | asyncio.timeout() context manager |
| Concurrency limit | asyncio.Semaphore |
| Sync bridge | asyncio.to_thread() |
| Cancellation | Always re-raise CancelledError |
Production-ready FastAPI patterns for lifespan, dependencies, middleware, and settings.
asynccontextmanager for startup/shutdown resource managementDepends().env and field validation| Decision | Recommendation |
|---|---|
| Lifespan | asynccontextmanager (not events) |
| Dependencies | Class-based services with DI |
| Settings | Pydantic Settings with .env |
| Response | ORJSONResponse for performance |
| Health | Check all critical dependencies |
Async database patterns with SQLAlchemy 2.0, AsyncSession, and FastAPI integration.
expire_on_commit=Falselazy="raise" on relationships to prevent accidental N+1 queriesselectinload for eager loading collections| Decision | Recommendation |
|---|---|
| Session scope | One AsyncSession per request |
| Lazy loading | lazy="raise" + explicit loads |
| Eager loading | selectinload for collections |
| expire_on_commit | False (prevents lazy load errors) |
| Pool | pool_pre_ping=True |
Database and HTTP connection pooling for high-performance async Python applications.
pool_size, max_overflow, pool_pre_pingmin_size/max_size and connection lifecycleTCPConnector limits and DNS cachingpool_size = (concurrent_requests / avg_queries_per_request) * 1.5
# NEVER use gather() for new code - no structured concurrency
# NEVER swallow CancelledError - breaks TaskGroup and timeout
# NEVER block the event loop with sync calls (time.sleep, requests.get)
# NEVER use global mutable state for db sessions
# NEVER skip dependency injection (create sessions in routes)
# NEVER share AsyncSession across tasks (race condition)
# NEVER use sync Session in async code (blocks event loop)
# NEVER create engine/pool per request
# NEVER forget to close pools on shutdown
ork:architecture-patterns - Clean architecture and layer separationork:async-jobs - Celery/ARQ for background processingstreaming-api-patterns - SSE/WebSocket async patternsork:database-patterns - Database schema designnpx claudepluginhub yonatangross/orchestkit --plugin orkProvides Python backend patterns for FastAPI, Django, SQLAlchemy, async code, and Pydantic v2. Covers principles like async usage, lifespan managers, and type annotations; includes references and stack detection script.
Provides expert Python backend patterns for Django, FastAPI, Flask: Pydantic models, dependency injection, background tasks, exception handling, lifespan events, async programming.
Provides FastAPI best practices including Pydantic models, SQLAlchemy ORM, async patterns, dependency injection, and JWT authentication for production Python APIs.