fastapi-patterns
OfficialFastAPI patterns for async APIs, dependency injection, Pydantic request and response models, OpenAPI docs, tests, security, and production readiness.
What this skill does
When applied, it prepends a system prompt before your request is sent — no extra calls and no change to how you are billed beyond the added tokens.
--- name: fastapi-patterns description: FastAPI patterns for async APIs, dependency injection, Pydantic request and response models, OpenAPI docs, tests, security, and production readiness. origin: community --- # FastAPI Patterns Production-oriented patterns for FastAPI services. ## When to Use - Building or reviewing a FastAPI app. - Splitting routers, schemas, dependencies, and database access. - Writing async endpoints that call a database or external service. - Adding authentication, authorization, OpenAPI docs, tests, or deployment settings. - Checking a FastAPI PR for copy-pasteable examples and production risks. ## How It Works Treat the FastAPI app as a thin HTTP layer over explicit dependencies and service code: - `main.py` owns app construction, middleware, exception handlers, and router registration. - `schemas/` owns Pydantic request and response models. - `dependencies.py` owns database, auth, pagination, and request-scoped dependencies. - `services/` or `crud/` owns business and persistence operations. - `tests/` overrides dependencies instead of opening production resources. Prefer small routers and explicit `response_model` declarations. Keep raw ORM objects, secrets, and framework globals out of response schemas. ## Project Layout ```text app/ |-- main.py |-- config.py |-- dependencies.py |-- exceptions.py |-- api/ | `-- routes/ | |-- users.py | `-- health.py |-- core/ | |-- security.py | `-- middleware.py |-- db/ | |-- session.py | `-- crud.py |-- models/ |-- schemas/ `-- tests/ ``` ## Application Factory Use a factory so tests and workers can build the app with controlled settings. ```python from contextlib import asynccontextmanager from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from app.api.routes import health, users from app.config import settings from app.db.session import close_db, init_db from app.exceptions import register_exception_handlers @asynccontextmanager async
Use this skill
Add a "skill" field with the skill’s ID to your chat completion request. It is applied server-side before your prompt is sent — no extra calls.
{
"model": "gpt-4o-mini",
"skill": "imp-e6c04b08-9ca1-40c1-a315-465363d25761",
"messages": [{ "role": "user", "content": "…" }]
}Install the skill, enable it in your dashboard and (optionally) limit it to specific models. It then applies automatically to every matching request — with no "skill" field to send each time.
Set it up in your dashboardMore skills
Delegate coding work to Codex, Claude Code, or OpenCode as background workers; not simple edits or read-only code lookup.
Create, edit, audit, tidy, validate, or restructure AgentSkills and SKILL.md files.
Search and analyze your own session logs (older/parent conversations) using jq.
Create, view, edit, delete, search, move, or export Apple Notes via the memo CLI on macOS.
Diagnose OpenClaw Android, iOS, or macOS node pairing, QR/setup code, route, auth, and connection failures.
Set up and use 1Password CLI for sign-in, desktop integration, and reading or injecting secrets.
List, add, edit, complete, or delete Apple Reminders and reminder lists via remindctl.
Create, search, and manage Bear notes via grizzly CLI.