Ecosystem: pip, FastAPI & Agents

FastAPI, Django placement, agent SDKs, and running Python in production.

Pick FastAPI for modern HTTP APIs, Django for batteries-included web apps, and agent SDKs when LLM tool loops are the product core.

Core concepts

  1. FastAPI: Type-hinted routes, automatic OpenAPI, async endpoints. — FastAPI tutorial
  2. Pydantic: Validation models — same shapes agent frameworks expect. — Pydantic docs
  3. Agent stacks: OpenAI Agents SDK, Pydantic-AI, smolagents — compare in our SDK roundup. — OpenAI Agents SDK
  4. Deployment: Docker + gunicorn/uvicorn workers; watch memory on long agent sessions. — FastAPI Docker deployment
  5. AI Agent roadmap: Continue on /roadmap/ai-agent-development after language basics.
python
from fastapi import FastAPI

app = FastAPI()

@app.get("/health")
async def health():
    return {"ok": True}

Concept videos

YouTube lessons for these topics. On a large screen they open in the reading panel next to the roadmap, same as the article links on each core concept.

Explanation

The Python ecosystem is layers of batteries — pick the layer that matches product shape instead of forcing one framework everywhere.

FastAPI

FastAPI uses type hints to validate requests and generate OpenAPI docs automatically. Async routes fit I/O-heavy APIs (LLM calls, webhooks). It is a sweet spot between minimal Flask and full Django.

Pydantic

Pydantic models are bouncers at the door — invalid JSON never enters your business logic. The same models appear in agent SDKs for tool arguments, keeping one schema for HTTP and LLM layers.

Agent stacks

Agent frameworks orchestrate model calls, tools, and memory. Compare SDKs by execution model (graph vs script), testing story, and deployment fit. Python dominates this space because integration libraries exist for everything.

Deployment

Containerize with Docker, run uvicorn/gunicorn workers, set health checks, and monitor memory — long agent sessions accumulate context. Scale horizontally when CPU or concurrent connections demand it.

AI Agent roadmap

Language fundamentals come first; the AI Agent Developer roadmap connects LLM providers, tools, sandboxes, and observability into a product-shaped path.

What Is It?

The Python web stack spans FastAPI, Django, ASGI servers, and WSGI legacy.

Agent SDKs (OpenAI Agents, Pydantic AI, etc.) sit on the same packaging and async patterns.

Production means gunicorn/uvicorn workers, env vars, and dependency pins.

Why Should I Care?

Most AI agent jobs still ship a Python HTTP service or worker alongside the model loop.

Choosing frameworks without understanding ASGI vs WSGI causes deployment surprises.

Real World Analogy

FastAPI is a express lane booth for HTTP: you declare routes, it validates types, and OpenAPI docs appear like receipt printers at checkout.

Visual Mental Model

text
FastAPI / Django
        |
  uvicorn / gunicorn
        |
  HTTP clients

Beginner Explanation

Pick FastAPI for typed APIs, Django when you want batteries included, agent SDKs when wiring LLM tools. All assume solid Python basics.

Smallest Possible Example

python
from fastapi import FastAPI
app = FastAPI()

@app.get("/")
def read_root():
    return {"ok": True}

Common Mistakes

❌ Running FastAPI with Flask's development server in production.

Use uvicorn/gunicorn with proper worker config.

❌ Pinning no versions in requirements.

Reproducible deploys need locked deps.

❌ Blocking DB drivers inside async routes without threadpool.

You stall the event loop — use async drivers or sync routes.

Real Project Example

Microsoft uses FastAPI in docs examples; Netflix uses Python for tooling and data.

Agent products from OpenAI and Anthropic ship Python-first SDKs.

Build This Mini Project

Stand up a one-route FastAPI app, hit it with curl, and export OpenAPI JSON. Note where types appear in the schema.

Interview Question

FastAPI vs Django — quick tradeoff?

FastAPI optimizes typed APIs and OpenAPI with minimal magic. Django gives ORM, admin, auth, and conventions for full web apps. Many teams use both in different services.

Key Takeaways

  • Match framework to product shape.
  • ASGI servers for async APIs.
  • Lock dependencies for deploys.
  • Agent SDKs still need HTTP and packaging skills.

Resources

The 60-second story

You have a language. Now you have a storefront. FastAPI is a counter where each window is a function, the sign on the window is a type hint, and the menu board (OpenAPI) writes itself from those signs. A customer asks for /orders. The hint says the body must look like a certain form. If they hand you a napkin, the counter rejects it before your business logic tries to read handwriting.

Pydantic is the form itself. It checks types, fills defaults, and gives you an object instead of a dict you hope has a "qty" key. Agent frameworks like that form because tools and model outputs need a shape, not a vibe.

An agent stack — OpenAI’s SDK, Pydantic-AI, smolagents — is hiring a clerk who can read the form, call the stock room, and try again. The web framework serves humans and other services. The agent framework serves a model that is confident and occasionally wrong. You want the form either way.

Deployment is moving the counter into a building that is not your laptop. Docker is the packed crate. uvicorn or gunicorn is how many people can stand at the counter at once. A long agent session can hold memory the way a chatty customer holds a table. Watch the room, not just the greeting.

Map the storefront.

  • A path function is a window.
  • Type hints and Pydantic are the form and the bouncer.
  • OpenAPI is the menu that stays in sync because it is generated.
  • An agent SDK is a clerk who may call the stock room several times.
  • Docker is the crate.
  • Workers are extra people at the counter.
  • The AI-agent roadmap is the next street over once the counter is boring and solid.
python
from pydantic import BaseModel

class Order(BaseModel):
    sku: str
    qty: int

That class is the whole idea in miniature. The model, the HTTP body, and the tool argument can share a shape. When they do not, you spend the week translating napkins.

FastAPI and Pydantic spread because untyped Flask handlers turn into folklore about which keys exist. Typed forms make the folklore into code. You still deploy them like any other service: a crate, a process, a limit on memory, a log when the clerk loops.

Mental model: a counter with forms, not a pile of napkins. The framework is the counter. The agent is a clerk who uses the same forms. Shipping is getting the counter out of your kitchen.

You can explain the page if you say: validate at the edge, generate the menu from the forms, and do not let an agent session be the thing that quietly fills the disk.

Threads in the same domain as this chapter — go deeper on iHateReading without leaving the roadmap.

Python AI agent SDKs in 2026: OpenAI vs Pydantic-AI vs smolagents vs Strands cover

Python AI agent SDKs in 2026: OpenAI vs Pydantic-AI vs smolagents vs Strands

Same three-tool agent in four frameworks — pick by execution model and testing needs.

AI Agent cover

AI Agent

What agents are and how they differ from a single chat completion.

Agent harnessing: the part of building AI agents nobody talks about cover

Agent harnessing: the part of building AI agents nobody talks about

Loop, tools, memory, sandbox, and tracing live in your code — not the model weights.

Smallest AI Agent cover

Smallest AI Agent

Minimal file-reading agent to learn LLM tool loops without framework magic.