Agent skill

fastapi

Provides comprehensive guidance for FastAPI framework including routing, request validation, dependency injection, async operations, OpenAPI documentation, and database integration. Use when the user asks about FastAPI, needs to create REST APIs, or build high-performance Python web services.

Stars 254
Forks 41

Install this agent skill to your Project

npx add-skill https://github.com/partme-ai/full-stack-skills/tree/main/skills/python-skills/fastapi

SKILL.md

When to use this skill

Use this skill whenever the user wants to:

  • Build REST or async APIs with FastAPI and Pydantic models
  • Implement dependency injection, authentication, or middleware
  • Configure routing, OpenAPI documentation, and deployment
  • Integrate with databases using async patterns

How to use this skill

Workflow

  1. Create app — instantiate FastAPI() and define route handlers
  2. Define models — use Pydantic for request/response validation
  3. Add dependencies — implement DI for auth, DB sessions, etc.
  4. Test and deploy — run with uvicorn, verify via /docs

Quick Start Example

python
from fastapi import FastAPI, HTTPException, Depends
from pydantic import BaseModel
from datetime import datetime

app = FastAPI(title="My API", version="1.0.0")

# Request/Response models
class ItemCreate(BaseModel):
    name: str
    price: float
    description: str | None = None

class ItemResponse(ItemCreate):
    id: int
    created_at: datetime

# Dependency example
async def get_db():
    db = SessionLocal()
    try:
        yield db
    finally:
        db.close()

# Route handlers
@app.post("/items/", response_model=ItemResponse, status_code=201)
async def create_item(item: ItemCreate, db=Depends(get_db)):
    db_item = Item(**item.model_dump())
    db.add(db_item)
    db.commit()
    return db_item

@app.get("/items/{item_id}", response_model=ItemResponse)
async def get_item(item_id: int, db=Depends(get_db)):
    item = db.query(Item).get(item_id)
    if not item:
        raise HTTPException(status_code=404, detail="Item not found")
    return item
bash
# Run the server
uvicorn main:app --reload

# Interactive docs available at http://localhost:8000/docs

Authentication Example

python
from fastapi.security import OAuth2PasswordBearer

oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")

@app.get("/users/me")
async def read_current_user(token: str = Depends(oauth2_scheme)):
    user = verify_token(token)
    if not user:
        raise HTTPException(status_code=401, detail="Invalid token")
    return user

Best Practices

  • Define explicit request and response schemas with Pydantic; use consistent status codes
  • Use async functions and database connection pools for high concurrency
  • Configure CORS middleware and security headers for production
  • Leverage automatic OpenAPI docs (/docs, /redoc) for API exploration
  • Use BackgroundTasks for non-blocking operations like email sending

Reference

Keywords

fastapi, async API, Pydantic, OpenAPI, dependency injection, Python web, REST API, uvicorn

Expand your agent's capabilities with these related and highly-rated skills.

partme-ai/full-stack-skills

ocrmypdf-batch

OCRmyPDF batch processing skill — process multiple PDFs, Docker automation, shell scripting, and CI/CD integration. Use when the user needs to OCR many PDFs, set up automated OCR pipelines, or integrate OCR into workflows.

254 41
Explore
partme-ai/full-stack-skills

ocrmypdf-optimize

OCRmyPDF optimization skill — compress PDFs, configure PDF/A output, JBIG2 encoding, and lossless optimization. Use when the user needs to reduce PDF file size, create archival PDF/A files, or optimize OCR output.

254 41
Explore
partme-ai/full-stack-skills

ocrmypdf-image

OCRmyPDF image processing skill — deskew, rotate, clean, despeckle, remove border from scanned documents. Use when the user needs to improve scanned PDF quality, fix skewed pages, remove noise, or clean up scanned documents before OCR.

254 41
Explore
partme-ai/full-stack-skills

ocrmypdf-api

OCRmyPDF Python API and plugin skill — use OCRmyPDF programmatically from Python, integrate with applications, and extend with plugins (EasyOCR, PaddleOCR, AppleOCR). Use when the user needs to call OCRmyPDF from Python code, build OCR pipelines, or use alternative OCR engines.

254 41
Explore
partme-ai/full-stack-skills

ocrmypdf

OCRmyPDF core skill — add searchable OCR text layer to scanned PDFs, convert images to searchable PDFs, support 100+ languages via Tesseract. Use when the user needs to OCR a PDF, make a scanned PDF searchable, or extract text from scanned documents.

254 41
Explore
partme-ai/full-stack-skills

svelte

Guides Svelte and SvelteKit development including reactive components, stores, transitions, lifecycle hooks, SSR, file-based routing, and deployment. Use when the user needs to build Svelte components, create SvelteKit applications, implement reactivity patterns, or configure Svelte with Vite.

254 41
Explore

Didn't find tool you were looking for?

Be as detailed as possible for better results