fastapi-python — Claude Code skill: FastAPI backend rules
Tells the agent how to write FastAPI code: async I/O, Pydantic v2 models, early returns and router layout. Useful when you build a Python API.
npx skills add Mindrally/skills --skill fastapi-python -a claude-codeWhat fastapi-python does
This skill turns the assistant into a FastAPI developer with a fixed set of conventions. Responses should be short and technical, with runnable Python examples. Pure functions get def, anything touching I/O gets async def, and Pydantic models replace raw dictionaries.
The file covers coding standards, error handling, FastAPI specifics and performance. Errors are handled at function entry with guard clauses and early returns; the happy path comes last. Routes carry return type annotations, startup and shutdown go through lifespan context managers, and expected failures are raised as HTTPException.
Dependencies are named directly: FastAPI, Pydantic v2, asyncpg or aiomysql, and SQLAlchemy 2.0. On a project with a different ORM or Pydantic v1, the model and serialization advice needs rework. Worth checking your versions before you rely on it.
What it helps with
- split FastAPI routes into modules without duplicated code
- move blocking database calls onto async
- define request and response schemas with Pydantic v2
- replace nested else blocks with guard clauses and early returns
- switch startup and shutdown events to a lifespan context manager
Example prompts for the agent
- add a create-order endpoint in
routers/order_routes.pyand validate the body with Pydantic - rewrite this handler as async and drop the blocking database call
- review my router: where should I add a guard clause and an HTTPException
How to install fastapi-python
1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill fastapi-python -a claude-code2Manually: put the files in place
~/.claude/skills/fastapi-python/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/fastapi-python/
1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill fastapi-python -a codex2Manually: put the files in place
.agents/skills/fastapi-python/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill fastapi-python -a cursor2Manually: put the files in place
.cursor/skills/fastapi-python/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install Mindrally/skills fastapi-python2Manually: put the files in place
.github/skills/fastapi-python/SKILL.md1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill fastapi-python -a gemini-cli2Platform CLI
gemini skills install https://github.com/Mindrally/skills --path fastapi-pythonManually: put the files in place
.devin/skills/fastapi-python/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add Mindrally/skills --skill fastapi-python -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
From the same set168
Similar
Nearby in Backend and APIs
Everything for Backend and APIs →Questions about fastapi-python
How do I install fastapi-python in Claude?
Run npx skills add Mindrally/skills --skill fastapi-python -a claude-code. The skill file then lands at ~/.claude/skills/fastapi-python/SKILL.md.
What does the fastapi-python skill do?
It sets the agent's rules for FastAPI work: async for I/O, Pydantic models for validation, early returns on errors, and lifespan for startup and shutdown.
What dependencies does it assume?
It names FastAPI, Pydantic v2, asyncpg or aiomysql, and SQLAlchemy 2.0. With Pydantic v1 the model and serialization examples need rewriting.
Source text
SKILL.md · Apache-2.0
--- name: fastapi-python description: Expert in FastAPI Python development with best practices for APIs and async operations metadata: maintainer: Mindrally source: https://github.com/Mindrally/skills --- # FastAPI Python You are an expert in FastAPI and Python backend development. ## Key Principles - Write concise, technical responses with accurate Python examples - Favor functional, declarative programming over class-based approaches - Prioritize modularization to eliminate code duplication - Use descriptive variable names with auxiliary verbs (e.g., `is_active`, `has_permission`) - Employ lowercase with underscores for file/directory naming (e.g., `routers/user_routes.py`) - Export routes and utilities explicitly - Follow the RORO (Receive an Object, Return an Object) pattern ## Python/FastAPI Standards - Use `def` for pure functions, `async def` for asynchronous operations - Use type hints for all function signatures. Prefer Pydantic models over raw dictionaries - Structure: exported router, sub-routes, utilities, static content, types (models, schemas) - Omit curly braces for single-line conditionals - Write concise one-line conditional syntax ## Error Handling - Handle edge cases at function entry points - Employ early returns for error conditions - Place happy path logic last - Avoid unnecessary else statements; use if-return patterns - Implement guard clauses for preconditions - Provide proper error logging and user-friendly messaging ## FastAPI-Specific Guidelines - Use functional components (plain functions) and Pydantic models for input validation - Declare routes with clear return type annotations - Prefer lifespan context managers for managing startup and shutdown events - Leverage middleware for logging, error monitoring, and optimization - Use HTTPException for expected errors and model them as specific HTTP responses - Apply Pydantic's BaseModel consistently for validation ## Performance Optimization - Minimize blocking I/O; use async for all database and API calls - Implement caching with Redis or in-memory stores - Optimize Pydantic serialization/deserialization - Use lazy loading for large datasets ## Key Conventions 1. Rely on FastAPI's dependency injection system 2. Prioritize API performance metrics (response time, latency, throughput) 3. Structure routes and dependencies for readability and maintainability ## Dependencies FastAPI, Pydantic v2, asyncpg/aiomysql, SQLAlchemy 2.0
© Mindrally · Apache-2.0 · Mindrally/skills