fastapi-patterns

fastapi-patterns is a skill for Claude Code, Codex from pyramidheadshark/claude-scaffold. It costs 0 tokens per session (1,458 once invoked), scanned A, original, MIT.

A set of coding patterns for FastAPI, a Python framework for building web APIs. It covers routers, data validation, dependencies, middleware, application startup, endpoints, and background tasks.

In plain words
What is it for?
Use it when building or changing FastAPI routers, Pydantic data models, HTTP endpoints, or application lifecycle code.
Why use it?
It gives a project a consistent structure and keeps web-request handling separate from business logic and external services.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/pyramidheadshark/claude-scaffold/fastapi-patterns
Any agent
npx skills add pyramidheadshark/claude-scaffold --skill fastapi-patterns
Clone the repo
git clone --depth 1 https://github.com/pyramidheadshark/claude-scaffold

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for fastapi-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/pyramidheadshark/claude-scaffold/fastapi-patterns.svg)](https://agentmods.dev/skills/pyramidheadshark/claude-scaffold/fastapi-patterns)
Your own site
<a href="https://agentmods.dev/skills/pyramidheadshark/claude-scaffold/fastapi-patterns"><img src="https://agentmods.dev/badge/skills/pyramidheadshark/claude-scaffold/fastapi-patterns.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,458 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.01458
Opus 5 $0.00000 $0.00729
Sonnet 5 $0.00000 $0.00292
Haiku 4.5 $0.00000 $0.00146

Measured 5d ago against content hash b3b953bdbcad, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-05, from the pricing page.

Security

Grade A, and why

fastapi-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/skills/fastapi-patterns/SKILL.md · 247 lines

How it starts

The opening of the file, as written. The whole thing — 247 lines — stays where its author put it; the contents beside it link to each section on GitHub.

FastAPI Patterns

When to Load This Skill

Load when working with: FastAPI routers, Pydantic models, dependency injection, middleware, ASGI lifecycle, HTTP endpoints, background tasks.

Architectural Contract

All FastAPI projects follow Hexagonal Architecture:

api/          → adapters IN  (HTTP boundary)
core/         → domain       (pure Python, zero framework imports)
services/     → application  (orchestrates core + adapters)
adapters/     → adapters OUT (DB, LLM, S3, external APIs)
models/       → schemas      (Pydantic — request, response, internal)

The core/ layer MUST NOT import from fastapi, sqlalchemy, or any adapter library. The api/ layer MUST NOT contain business logic — only validation and routing.

Application Entry Point

from contextlib import asynccontextmanager

from fastapi import FastAPI

from src.project_name.api.routers import health, items
from src.project_name.core.config import settings


@asynccontextmanager
async def lifespan(app: FastAPI):
    yield


def create_app() -> FastAPI:
    app = FastAPI(
        title=settings.app_name,
        version=settings.app_version,
        lifespan=lifespan,
    )
    app.include_router(health.router, prefix="/health", tags=["health"])
    app.include_router(items.router, prefix="/api/v1/items", tags=["items"])
    return app


app = create_app()

Router Pattern

from fastapi import APIRouter, Depends, HTTPException, status

from src.project_name.models.item import ItemCreate, ItemResponse
from src.project_name.services.item_service import ItemService

router = APIRouter()


def get_item_service() -> ItemService:
    return ItemService()


@router.post("/", response_model=ItemResponse, status_code=status.HTTP_201_CREATED)
async def create_item(
    payload: ItemCreate,
    service: ItemService = Depends(get_item_service),
) -> ItemResponse:
    return await service.create(payload)

Service Layer Pattern

from src.project_name.adapters.item_repository import ItemRepository
from src.project_name.core.domain import Item
from src.project_name.models.item import ItemCreate, ItemResponse


class ItemService:
    def __init__(self, repository: ItemRepository | None = None) -> None:
        self._repo = repository or ItemRepository()

    async def create(self, payload: ItemCreate) -> ItemResponse:
        domain_item = Item.from_create(payload)
        saved = await self._repo.save(domain_item)
        return ItemResponse.model_validate(saved)

Read the full file on GitHub · 247 lines

Files

What ships with it

4 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 247 lines · 0 tokens per session scan A b3b953bdbcad

Subscribe to this mod's changes

fastapi-patterns is a skill published in the GitHub repository pyramidheadshark/claude-scaffold (4 stars, last pushed 4mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,458 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

mle-workflow

Production ML engineering workflow — data contracts, reproducible training, evaluation gates, deployment, and monitoring. Use when building, reviewing, or hardening ML systems beyond notebooks.

chandrudp29/skillhub · 39 tokens

data-scientist

!cat Claude-Production-Grade-Suite/.protocols/ux-protocol.md 2>/dev/null || true !cat Claude-Production-Grade-Suite/.protocols/input-validation.md 2>/dev/null || true !cat Claude-Production-Grade-Suite/.protocols/tool-efficiency.md 2>/dev/null || true !cat Claude-Production-Grade-Suite/.protocols/visual-identity.md…

nagisanzenin/production-grade · 43 tokens

ai-engineer

Builds production AI/ML systems — model training, fine-tuning, MLOps pipelines, model serving, evaluation frameworks, RAG optimization, and agent orchestration at scale. Use when the user asks to build, train, or deploy ML models, set up MLOps pipelines, optimize RAG systems, create inference endpoints, or design…

buiphucminhtam/forgewright · 78 tokens

data-scientist

!cat skills/shared/protocols/ux-protocol.md 2>/dev/null || true !cat skills/shared/protocols/input-validation.md 2>/dev/null || true !cat skills/shared/protocols/tool-efficiency.md 2>/dev/null || true !cat .production-grade.yaml 2>/dev/null || echo "No config — using defaults".

buiphucminhtam/forgewright · 52 tokens

ai-ml-engineering

AI/ML Engineering Review: Reviews AI/ML systems for production readiness — model serving, MLOps pipelines, LLM integration patterns, prompt engineering, evaluation frameworks, and responsible AI. Covers model deployment, feature stores, experiment tracking, monitoring/drift detection, and AI safety. Use when the user…

camilooscargbaptista/cto-toolkit · 112 tokens

git-hooks-manager

Setup and manage git hooks for pre-commit, pre-push automation (lint, test, format).

glincker/claude-code-marketplace · 25 tokens