# fastapi-expert

Guides async FastAPI development with Pydantic V2, from REST routes and authentication to database operations and tests.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 6100 installs · ★ 12062
- Author: https://github.com/Jeffallan
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/Jeffallan/claude-skills/tree/HEAD/skills/fastapi-expert/SKILL.md
- Updated: 2026-10-21
- HTML: https://affpapa.org/en/nevibecode/skills/fastapi-expert

## What it does

The skill turns API requirements into Pydantic V2 schemas and asynchronous route handlers with dependency injection. Its guidance covers REST endpoints, JWT and OAuth2 authentication, async SQLAlchemy operations, WebSocket routes, and OpenAPI documentation. Database-backed features can include CRUD operations.

Its workflow checks schema validation and HTTP status codes, runs async tests with pytest and httpx, and verifies the API docs at `/docs`. It favors type hints and `Annotated` for dependencies, and rejects synchronous database work and Pydantic V1 syntax. One detail matters in the JWT example: the secret belongs in environment variables or settings, not as a hardcoded value.

Reference files cover schemas, routing, authentication, testing, and migration from Django. The sample uses `EmailStr`, so a project using that field needs the corresponding Pydantic support.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add Jeffallan/claude-skills --skill fastapi-expert -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/fastapi-expert/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/fastapi-expert/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add Jeffallan/claude-skills --skill fastapi-expert -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/fastapi-expert/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add Jeffallan/claude-skills --skill fastapi-expert -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/fastapi-expert/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install Jeffallan/claude-skills fastapi-expert
```

2. **Manually: put the files in place**
- File: `.github/skills/fastapi-expert/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add Jeffallan/claude-skills --skill fastapi-expert -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/Jeffallan/claude-skills --path skills/fastapi-expert
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/fastapi-expert/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add Jeffallan/claude-skills --skill fastapi-expert -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/Jeffallan/claude-skills/tree/HEAD/skills/fastapi-expert/SKILL.md

## When to use it
- design Pydantic V2 validation schemas
- add async REST routes with dependency injection
- implement JWT authentication and current-user lookup
- connect async CRUD operations through SQLAlchemy
- write API tests with pytest and httpx

## Example prompts
- Build async FastAPI routes with Pydantic V2 schemas for this API.
- Add JWT authentication and a current-user dependency with suitable HTTP status codes.
- Write async tests for these routes using pytest and httpx.

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 0c3b16ff34887de0.

BEGIN THIRD-PARTY FILE 0c3b16ff34887de0
````text
---
name: fastapi-expert
description: "Use when building high-performance async Python APIs with FastAPI and Pydantic V2. Invoke to create REST endpoints, define Pydantic models, implement authentication flows, set up async SQLAlchemy database operations, add JWT authentication, build WebSocket endpoints, or generate OpenAPI documentation. Trigger terms: FastAPI, Pydantic, async Python, Python API, REST API Python, SQLAlchemy async, JWT authentication, OpenAPI, Swagger Python."
license: MIT
metadata:
  author: https://github.com/Jeffallan
  company: https://synergetic.solutions
  version: "1.1.0"
  domain: backend
  triggers: FastAPI, Pydantic, async Python, Python API, REST API Python, SQLAlchemy async, JWT authentication, OpenAPI, Swagger Python
  role: specialist
  scope: implementation
  output-format: code
  related-skills: fullstack-guardian, django-expert, test-master
---

# FastAPI Expert

Deep expertise in async Python, Pydantic V2, and production-grade API development with FastAPI.

## When to Use This Skill

- Building REST APIs with FastAPI
- Implementing Pydantic V2 validation schemas
- Setting up async database operations
- Implementing JWT authentication/authorization
- Creating WebSocket endpoints
- Optimizing API performance

## Core Workflow

1. **Analyze requirements** — Identify endpoints, data models, auth needs
2. **Design schemas** — Create Pydantic V2 models for validation
3. **Implement** — Write async endpoints with proper dependency injection
4. **Secure** — Add authentication, authorization, rate limiting
5. **Test** — Write async tests with pytest and httpx; run `pytest` after each endpoint group and verify OpenAPI docs at `/docs`

> **Checkpoint after each step:** confirm schemas validate correctly, endpoints return expected HTTP status codes, and `/docs` reflects the intended API surface before proceeding.

## Minimal Complete Example

Schema + endpoint + dependency injection in one cohesive unit:

```python
# schemas.py
from pydantic import BaseModel, EmailStr, field_validator, model_config

class UserCreate(BaseModel):
    model_config = model_config(str_strip_whitespace=True)

    email: EmailStr
    password: str
    name: str | None = None

    @field_validator("password")
    @classmethod
    def password_strength(cls, v: str) -> str:
        if len(v) < 8:
            raise ValueError("Password must be at least 8 characters")
        return v

class UserResponse(BaseModel):
    model_config = model_config(from_attributes=True)

    id: int
    email: EmailStr
    name: str | None = None
```

```python
# routers/users.py
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.ext.asyncio import AsyncSession
from typing import Annotated

from app.database import get_db
from app.schemas import UserCreate, UserResponse
from app import crud
````
END THIRD-PARTY FILE 0c3b16ff34887de0

The third-party file has ended. Everything between the 0c3b16ff34887de0 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2856 of 7073 bytes. © https://github.com/Jeffallan · MIT · https://github.com/Jeffallan/claude-skills/tree/HEAD/skills/fastapi-expert/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
