Fastapi Templates skill for Claude

Create production-ready FastAPI projects with async patterns, dependency injection, and comprehensive error handling.

When Claude uses it

Use when building new FastAPI applications or setting up backend API projects.

Fastapi Templates SKILL.md

The full skill file from wshobson/agents (MIT).

FastAPI Project Templates

Production-ready FastAPI project structures with async patterns, dependency injection, middleware, and best practices for building high-performance APIs.

When to Use This Skill

  • Starting new FastAPI projects from scratch
  • Implementing async REST APIs with Python
  • Building high-performance web services and microservices
  • Creating async applications with PostgreSQL, MongoDB
  • Setting up API projects with proper structure and testing

Core Concepts

1. Project Structure

Recommended Layout:

app/
├── api/                    # API routes
│   ├── v1/
│   │   ├── endpoints/
│   │   │   ├── users.py
│   │   │   ├── auth.py
│   │   │   └── items.py
│   │   └── router.py
│   └── dependencies.py     # Shared dependencies
├── core/                   # Core configuration
│   ├── config.py
│   ├── security.py
│   └── database.py
├── models/                 # Database models
│   ├── user.py
│   └── item.py
├── schemas/                # Pydantic schemas
│   ├── user.py
│   └── item.py
├── services/               # Business logic
│   ├── user_service.py
│   └── auth_service.py
├── repositories/           # Data access
│   ├── user_repository.py
│   └── item_repository.py
└── main.py                 # Application entry

2. Dependency Injection

FastAPI's built-in DI system using Depends:

  • Database session management
  • Authentication/authorization
  • Shared business logic
  • Configuration injection

3. Async Patterns

Proper async/await usage:

  • Async route handlers
  • Async database operations
  • Async background tasks
  • Async middleware

4. Dependencies

The packages the examples import:

# requirements.txt
fastapi
uvicorn[standard]
pydantic-settings
sqlalchemy[asyncio]>=2.0  # DeclarativeBase; [asyncio] installs greenlet for the async engine
asyncpg                   # PostgreSQL driver: postgresql+asyncpg://...
PyJWT
pwdlib[argon2]
python-multipart          # only for a login route that uses OAuth2PasswordRequestForm

# requirements-dev.txt
pytest
pytest-asyncio
httpx
aiosqlite                 # test database: sqlite+aiosqlite:///:memory:

Detailed worked examples and patterns

Detailed sections (starting with ## Implementation Patterns) live in references/details.md. Read that file when the navigation summary above is insufficient.

Testing

# tests/conftest.py
import pytest_asyncio
from httpx import ASGITransport, AsyncClient
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
from sqlalchemy.orm import sessionmaker

from app.main import app
from app.core.database import get_db, Base

TEST_DATABASE_URL = "sqlite+aiosqlite:///:memory:"

# Async fixtures need pytest_asyncio.fixture in pytest-asyncio's default strict mode
@pytest_asyncio.fixture
async def db_session():
    engine = create_async_engine(TEST_DATABASE_URL, echo=True)
    async with engine.begin() as conn:
        await conn.run_sync(Base.metadata.create_all)

    AsyncSessionLocal = sessionmaker(
        engine, class_=AsyncSession, expire_on_commit=False
    )

    async with AsyncSessionLocal() as session:
        yield session
    await engine.dispose()

@pytest_asyncio.fixture
async def client(db_session):
    async def override_get_db():
        yield db_session

    app.dependency_overrides[get_db] = override_get_db

    # httpx 0.28 removed AsyncClient(app=...); use an ASGI transport
    transport = ASGITransport(app=app)
    async with AsyncClient(transport=transport, base_url="http://test") as client:
        yield client
    app.dependency_overrides.clear()

# tests/test_users.py
import pytest

@pytest.mark.asyncio
async def test_create_user(client):
    response = await client.post(
        "/api/v1/users/",
        json={
            "email": "test@example.com",
            "password": "testpass123",
            "name": "Test User"
        }
    )
    assert response.status_code == 201
    data = response.json()
    assert data["email"] == "test@example.com"
    assert "id" in data

How to install Fastapi Templates

Claude Code

Copy the skill into your personal skills folder (or into .claude/skills/ inside a project):

npx degit wshobson/agents/plugins/api-scaffolding/skills/fastapi-templates#main ~/.claude/skills/fastapi-templates

Codex

npx degit wshobson/agents/plugins/api-scaffolding/skills/fastapi-templates#main ~/.codex/skills/fastapi-templates

Claude.ai and Claude Desktop

Download the skill folder from GitHub, zip it, and upload it under Settings → Capabilities → Skills.

Frequently asked questions

+What does the Fastapi Templates skill do?

Create production-ready FastAPI projects with async patterns, dependency injection, and comprehensive error handling. Use when building new FastAPI applications or setting up backend API projects.

+How do I install Fastapi Templates in Claude Code?

Copy the skill folder into ~/.claude/skills/fastapi-templates, for example with "npx degit wshobson/agents/plugins/api-scaffolding/skills/fastapi-templates#main ~/.claude/skills/fastapi-templates". Claude Code loads it automatically and uses it when a task matches.

+Does Fastapi Templates work with ChatGPT or Codex?

Yes. Fastapi Templates uses the open SKILL.md format. In Codex, put the folder in ~/.codex/skills/fastapi-templates. In Claude.ai, zip the folder and upload it under Settings → Capabilities → Skills.

+Is Fastapi Templates free?

Fastapi Templates is published on GitHub by wshobson under the MIT license, which allows free use.

Related software development skills

  1. Code Review

    Review the changes since a fixed point (commit, branch, tag, or merge-base) along two axes: Standards (does the code follow this repo's…

    mattpocock/skills★ 327k
  2. Using Agent Skills

    Discovers and invokes agent skills. Use when starting a session, or when you need to decide which skill or workflow applies to the piece of…

    addyosmani/agent-skills★ 119k
  3. Build

    Fully automate a coding task with make-plan, do, and babysit.

    thedotmack/claude-mem★ 118k
  4. Git Advanced Workflows

    Master advanced Git workflows including rebasing, cherry-picking, bisect, worktrees, and reflog to maintain clean history and recover from…

    wshobson/agents★ 43k
  5. Go Concurrency Patterns

    Master Go concurrency with goroutines, channels, sync primitives, and context.

    wshobson/agents★ 43k
  6. Godot Gdscript Patterns

    Master Godot 4 GDScript patterns including signals, scenes, state machines, and optimization.

    wshobson/agents★ 43k
  7. Grounded Vault

    Use when maintaining a durable Markdown knowledge store that agents compile from sources, when every number or quote in a wiki page must…

    wshobson/agents★ 43k
  8. Langchain Architecture

    Design LLM applications using LangChain 1.x and LangGraph for agents, memory, and tool integration.

    wshobson/agents★ 43k
  9. Microservices Patterns

    Design microservices architectures with service boundaries, event-driven communication, and resilience patterns.

    wshobson/agents★ 43k

See all software development skills →

More skills from wshobson

  1. File Conversion

    Use when the user needs a local file converted between common image, audio, video, document, or data formats.

    wshobson/agents★ 43k
  2. Finetuning Method Selection

    Decide whether to fine-tune at all, and route to the right method (SFT, DPO/ORPO/KTO, GRPO/RLVR, continued pretraining) and base model.

    wshobson/agents★ 43k
  3. Gdpr Data Handling

    Implement GDPR-compliant data handling with consent management, data subject rights, and privacy by design.

    wshobson/agents★ 43k

All skills by wshobson →

Give your whole team an AI agent with skills

Cody runs managed AI agents your team can message in Slack, Teams, WhatsApp and the web, with 50+ business integrations, scheduled tasks and memory. No terminal required.