FastAPI

FastAPI: the framework that made Python APIs feel modern. Type hints become validation, validation becomes docs — Swagger UI for free.

▶ Watch this reel

What you'll learn

  1. Routes & models
  2. Dependency injection
  3. Middleware, background & streaming
  4. Auth & docs

Remember this

Routes & models

Dependency injection

Middleware / background / streaming

Auth & docs

Code: A minimal production-shaped FastAPI skeleton

from fastapi import FastAPI, Depends, HTTPException
from pydantic import BaseModel, Field
from sse_starlette.sse import EventSourceResponse

app = FastAPI(title="RAG Service")

class Ask(BaseModel):
    question: str = Field(min_length=3)
    stream: bool = True

async def get_store():
    async with VectorStore.connect() as vs:   # per-request, auto-close
        yield vs

@app.post("/ask")
async def ask(
    req: Ask,
    user: User = Depends(get_current_user),
    store: VectorStore = Depends(get_store),
):
    async def gen():
        async for token in rag.stream(req.question, store):
            yield {"data": token}
    return EventSourceResponse(gen())

# Run:  uvicorn app:app --reload
# Docs: http://localhost:8000/docs  ← Swagger UI, already complete