Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsBlogPro
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges
  • Chrome Extension
  • Skill Manager

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Fastapi

ASecurity

Build high-performance Python APIs with FastAPI: routing, Pydantic validation, async, dependency injection, OpenAPI, and testing. Use for any Python backend.

2 stars
0 votes
0 copies
0 views
Added 9/29/2026
ai-agentspythongobashsqlfastapitestingapibackendperformance

Works with

cliapi

Security Analysis

A96/100
mediumInstalls packages at runtime which could introduce malicious dependencies

Pro scans all 2 files and shows the line behind each finding

Scanned 9/29/2026

$npx -y skills add ssrjkk/claude-skills --skill fastapi --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Fastapi?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Fastapi
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ssrjkk-fastapi/badge)](https://www.skillsdirectory.com/skills/ssrjkk-fastapi)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
Files
SKILL.md
---
name: fastapi
description: "Build high-performance Python APIs with FastAPI: routing, Pydantic validation, async, dependency injection, OpenAPI, and testing. Use for any Python backend."
category: backend
tags: [fastapi, python, api, async, pydantic, openapi, backend]
models: [sonnet, opus, gpt-5, gemini-2.5, glm-4.6]
version: 1.0.0
author: ssrjkk
created: 2026-09-20
updated: 2026-09-28
---
# FastAPI

> High-performance Python API framework with automatic OpenAPI docs.

## Quick Start
```bash
pip install fastapi uvicorn
uvicorn main:app --reload
# http://localhost:8000/docs  (Swagger UI)
```

## When to Use
- REST or async APIs in Python
- Microservices and serverless handlers
- Projects needing validation, typed contracts, and OpenAPI schema
- Async workloads (HTTP clients, WebSockets, background tasks)

## Best Practices

### Structure
- Organize by feature: `routers/`, `schemas/`, `services/`, `models/`
- Use APIRouter per resource; include them in the app
- Keep business logic in services, not in route handlers
- Put Pydantic schemas in a dedicated module

### Validation & Types
- Define request/response models with Pydantic
- Use `Depends` for shared logic (auth, DB sessions)
- Set `response_model` on every endpoint
- Prefer `Annotated` dependencies for clarity

### Async
- Use `async def` for I/O-bound endpoints
- Prefer async SQLAlchemy/asyncpg for DB access
- Offload CPU-bound work to a threadpool (`run_in_executor`)
- Avoid blocking calls in the event loop

## Dependencies
```bash
pip install fastapi uvicorn[standard] pydantic
pip install -D pytest httpx pytest-asyncio
```

## Examples
```python
from fastapi import FastAPI, Depends, HTTPException
from pydantic import BaseModel
from typing import Annotated

app = FastAPI(title="Items API")

class Item(BaseModel):
    name: str
    price: float

class ItemOut(BaseModel):
    id: int
    name: str
    price: float

def get_session():
    # injected dependency
    yield {"conn": "pool"}

@app.post("/items", response_model=ItemOut, status_code=201)
async def create_item(item: Item, session: Annotated[dict, Depends(get_session)]):
    return ItemOut(id=1, **item.model_dump())
```
```python
# Router pattern
from fastapi import APIRouter

router = APIRouter(prefix="/users", tags=["users"])

@router.get("/{user_id}")
async def get_user(user_id: int):
    if user_id < 0:
        raise HTTPException(status_code=400, detail="Invalid id")
    return {"id": user_id}
```
```python
# Async DB with asyncpg
import asyncpg
from fastapi import Depends

async def get_pool():
    pool = await asyncpg.create_pool(dsn="postgres://localhost/app")
    try:
        yield pool
    finally:
        await pool.close()
```
```python
# Background task
from fastapi import BackgroundTasks

async def send_email(email: str):
    pass  # send in background

@app.post("/notify")
async def notify(email: str, bg: BackgroundTasks):
    bg.add_task(send_email, email)
    return {"ok": True}
```

## Step-by-Step
1. Scaffold: create `main.py` with the FastAPI app and import routers.
2. Define Pydantic schemas for every request and response model.
3. Write route handlers with `response_model` and correct status codes.
4. Add dependencies (`Depends`) for auth, DB sessions, and settings.
5. Use async handlers and async DB drivers for concurrency.
6. Add exception handlers for consistent error responses.
7. Write tests with `httpx` + `pytest`; override dependencies for isolation.
8. Validate the generated OpenAPI schema in CI; lock your dependencies.

## Validation
1. `uvicorn main:app` starts cleanly
2. `/docs` renders schemas with correct types
3. `pytest` passes (unit + integration with TestClient)
4. Invalid input returns 422 with Pydantic details
5. Response models match declared schemas

## Troubleshooting
- 422 on valid input: check Pydantic field types vs JSON types.
- Slow async endpoints: look for blocking sync calls in `async def`.
- Circular imports: move schemas to a shared module.

Attribution

ssrjkkssrjkk
View sourceSee grades on GitHubMore from ssrjkk →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Caveman

Terse caveman voice: answer first, fluff gone, every technical fact kept. Use for /caveman, "caveman mode", "talk like caveman", "be brief", "less tokens". Stays on until "stop caveman" or "normal mode".

1100021 votes

Hyperplan

Adversarial multi-agent planning skill. Self-orchestrates 5 hostile category members (unspecified-low, unspecified-high, deep, ultrabrain, artistry) via team-mode for ruthless cross-critique debate, distills only the defensible insights, then MANDATORILY hands the distilled insight bundle to the `plan` agent for executable plan formalization. Use when planning needs maximum rigor and surfacing of weak assumptions, blind spots, and over-engineering. Triggers: 'hyperplan', 'hpp', '/hyperplan', ...

698461 votes

Writing Skills

Create and manage Claude Code skills in HASH repository following Anthropic best practices. Use when creating new skills, modifying skill-rules.json, understanding trigger patterns, working with hooks, debugging skill activation, or implementing progressive disclosure. Covers skill structure, YAML frontmatter, trigger types (keywords, intent patterns), UserPromptSubmit hook, and the 500-line rule. Includes validation and debugging with SKILL_DEBUG. Examples include rust-error-stack, cargo-dep...

3931 votes

Mcp Code Execution

Routes multi-tool workflows through MCP servers for large datasets and pipelines. Use when Bash tool overhead is limiting throughput on data-heavy tasks.

3421 votes

catchup

Recovers the conversation and failed tool calls of a previous Codex, Amp, Claude Code, Antigravity, Cline, Copilot CLI, Cursor, DeepSeek Harness, Grok Build, Kimi, OpenCode, Pi Agent, or ZCode session. Use when the user says "catch up", "what did the last session do", "get me up to speed", "I switched agents", asks to recover/summarize a previous session before continuing, or asks to diagnose or report a catchup failure. Do NOT use for the current conversation, git history, or any non-agent log.

741 votes
View all in ai-agents →