Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
yonatangross avatar

Python Backend

  • 174 installs
  • 213 repo stars
  • Updated August 4, 2026
  • yonatangross/orchestkit

Scaffold FastAPI or similar Python services, data models, auth, and integration layers that power OrchestKit orchestration APIs and worker backends.

About

OrchestKit python-backend skill covers building production Python APIs and services—project layout, FastAPI patterns, persistence, authentication, integrations, and error handling—for SaaS orchestration backends that expose agent workflows over HTTP.

  • FastAPI service structure
  • Data models and persistence
  • Auth and middleware patterns
  • External API integrations
  • Error handling conventions

Python Backend by the numbers

  • 174 all-time installs (skills.sh)
  • +2 installs in the week ending Jul 28, 2026 (Skillselion tracking)
  • Ranked #70 of 290 Python skills by installs in the Skillselion catalog
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/yonatangross/orchestkit --skill python-backend

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs174
repo stars213
Last updatedAugust 4, 2026
Repositoryyonatangross/orchestkit

What it does

Scaffold FastAPI or similar Python services, data models, auth, and integration layers that power OrchestKit orchestration APIs and worker backends.

Files

SKILL.mdMarkdownGitHub ↗

<!-- directive-density: intentional (teaches asyncio/SQLAlchemy anti-patterns; NEVER markers describe real event-loop/race-condition bugs, not aspirational guidance) -->

Python Backend

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.

Quick Reference

CategoryRulesImpactWhen to Use
Asyncio3HIGHTaskGroup, structured concurrency, cancellation handling
FastAPI3HIGHDependencies, middleware, background tasks
SQLAlchemy3HIGHAsync sessions, relationships, migrations
Pooling3MEDIUMDatabase pools, HTTP sessions, tuning

Total: 12 rules across 4 categories

Quick Start

# 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

# Reusable dependency alias (FastAPI's recommended Annotated form)
SessionDep = Annotated[AsyncSession, Depends(get_db)]

@router.get("/users/{user_id}")
async def get_user(user_id: UUID, db: SessionDep):
    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]

Asyncio

Modern Python asyncio patterns using structured concurrency, TaskGroup, and Python 3.11+ features.

Key Patterns

  • TaskGroup replaces gather() with structured concurrency and auto-cancellation
  • `asyncio.timeout()` context manager for composable timeouts
  • Semaphore for concurrency limiting (rate-limit HTTP requests)
  • *`except`** with ExceptionGroup for handling multiple task failures
  • `asyncio.to_thread()` for bridging sync code to async

Key Decisions

DecisionRecommendation
Task spawningTaskGroup not gather()
Timeoutsasyncio.timeout() context manager
Concurrency limitasyncio.Semaphore
Sync bridgeasyncio.to_thread()
CancellationAlways re-raise CancelledError

FastAPI

Production-ready FastAPI patterns for lifespan, dependencies, middleware, and settings.

Key Patterns

  • Lifespan with asynccontextmanager for startup/shutdown resource management
  • Dependency injection with class-based services and Depends()
  • Middleware stack: CORS -> RequestID -> Timing -> Logging
  • Pydantic Settings with .env and field validation
  • Exception handlers with RFC 9457 Problem Details

Key Decisions

DecisionRecommendation
Lifespanasynccontextmanager (not events)
DependenciesClass-based services with DI
SettingsPydantic Settings with .env
ResponseORJSONResponse for performance
HealthCheck all critical dependencies

SQLAlchemy

Async database patterns with SQLAlchemy 2.0, AsyncSession, and FastAPI integration.

Key Patterns

  • One AsyncSession per request with expire_on_commit=False
  • `lazy="raise"` on relationships to prevent accidental N+1 queries
  • `selectinload` for eager loading collections
  • Repository pattern with generic async CRUD
  • Bulk inserts chunked 1000-10000 rows for memory management

Key Decisions

DecisionRecommendation
Session scopeOne AsyncSession per request
Lazy loadinglazy="raise" + explicit loads
Eager loadingselectinload for collections
expire_on_commitFalse (prevents lazy load errors)
Poolpool_pre_ping=True

Pooling

Database and HTTP connection pooling for high-performance async Python applications.

Key Patterns

  • SQLAlchemy pool with pool_size, max_overflow, pool_pre_ping
  • Direct asyncpg pool with min_size/max_size and connection lifecycle
  • aiohttp session with TCPConnector limits and DNS caching
  • FastAPI lifespan creating and closing pools at startup/shutdown
  • Pool monitoring with Prometheus metrics

Pool Sizing Formula

pool_size = (concurrent_requests / avg_queries_per_request) * 1.5

Anti-Patterns (FORBIDDEN)

# 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

Related Skills

  • ork:architecture-patterns - Clean architecture and layer separation
  • ork:async-jobs - Celery/ARQ for background processing
  • streaming-api-patterns - SSE/WebSocket async patterns
  • ork:database-patterns - Database schema design

Related skills

Pythonbackendintegrations

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.