FastAPI, Django, Flask and Litestar compared on the properties that decide how well Claude Code, Cursor and Codex work in a Python backend, plus how Encore adds the infrastructure to whichever you pick.
A coding agent writing a Python backend spends most of its time doing what a new hire does: reading the existing code to find where things go, copying a pattern, running the tests and fixing what broke, and the framework decides how much of that is obvious.
FastAPI, Flask and Django are the three most used Python web frameworks in the 2025 Stack Overflow survey, at 14.8, 14.4 and 12.6 percent of respondents. They differ in how much structure an agent gets from the framework itself, and none of them help when the change needs a new Postgres table or a queue, which is where an agent working in a Python repo usually stops being able to test its own work.
What makes a framework work well with an agent:
Encore combines the Python web framework you already use with infrastructure declared in the same code, as an SDK you install into the existing app. Routing, validation and request handling stay in FastAPI, Django or Flask, while Postgres databases, Pub/Sub topics, object storage, Redis, cron jobs and secrets are module-level declarations that Encore finds and provisions. encore run starts the databases, topics and buckets locally next to the app, and a deploy provisions the same declarations in your own AWS or GCP account.

For an agent this means a change that needs a table or a queue no longer stops at the edge of the repo, because the agent declares the resource in the same file as the handler that uses it, runs the app with real local services, calls the endpoint and checks the result:
from contextlib import asynccontextmanager
import encore
from encore import pubsub
from encore.storage import postgres
from fastapi import FastAPI
from pydantic import BaseModel
# Encore finds these declarations and provisions them
# locally, in preview environments, and in your cloud.
db = postgres.Database("users", migrations="./migrations")
signups = pubsub.Topic("signups")
@asynccontextmanager
async def lifespan(app: FastAPI):
await encore.start()
yield
app = FastAPI(lifespan=lifespan)
class Signup(BaseModel):
email: str
@app.post("/users", status_code=201)
async def create_user(req: Signup) -> dict:
row = await db.query(
"INSERT INTO users (email) VALUES ($1) RETURNING id", req.email
).one()
await signups.publish({"user_id": row["id"], "email": req.email})
return {"id": row["id"]}
Encore connects the app to the resources at runtime, and agents declare infrastructure in code while the cloud access sits with Encore's IAM role, not the agent. Capacity, networking and backups are set per environment outside the code. The AI integration generates project rules for Claude Code, Cursor or AGENTS.md and connects a local MCP server that lets the agent read the database schema and the traces of the requests it made. For code that attaches the SDK to each framework, see FastAPI vs Django vs Flask, and for a full deploy, deploying FastAPI to AWS.
Python support is in beta, and you can sign up for access.
FastAPI builds on Starlette and Pydantic, and the function signature declares the path, query and body parameters that FastAPI validates and documents. For an agent this means the shape of an endpoint is in one place, and a wrong field type fails validation in a test rather than in production. FastAPI's TestClient calls the app in-process with no server running, which makes it a fast check to run after every edit.
from fastapi import FastAPI
from fastapi.testclient import TestClient
from pydantic import BaseModel
app = FastAPI()
class Signup(BaseModel):
email: str
@app.post("/users", status_code=201)
async def create_user(req: Signup) -> dict:
return {"email": req.email}
def test_create_user():
client = TestClient(app)
res = client.post("/users", json={"email": "a@example.com"})
assert res.status_code == 201
FastAPI leaves the ORM, migrations, auth and project layout to the team, so an agent in a FastAPI repo follows whatever conventions the repo already has. A short CLAUDE.md or AGENTS.md that names the ORM and the folder layout closes most of that gap.
Django ships an ORM, migrations, an admin, auth and a test runner, and every project uses the same layout of apps, models, views and URLs. An agent adding a field edits the model and runs makemigrations, and the Django test runner creates a separate test database for every run, so the agent can test real queries without touching development data.
# models.py
from django.db import models
class User(models.Model):
email = models.EmailField(unique=True)
created_at = models.DateTimeField(auto_now_add=True)
The conventions help most in large apps, although the surface is big and an API can be built with Django REST framework, django-ninja or plain views, so a repo that mixes them gives the agent conflicting patterns to copy.
Flask is small enough that the agent rarely needs documentation for the framework itself. Validation, data access and structure come from extensions, so the agent's output depends on which ones the repo uses and how consistently.
Flask works well for small services and internal tools, while in a larger codebase without conventions written down, the agent will invent structure in each change.
Litestar has typed route handlers, dependency injection, DTOs and a SQLAlchemy plugin, which gives an agent more structure than FastAPI. It has less public code and fewer published examples than FastAPI, so pointing the agent at its documentation and an existing handler in the repo matters more.
Litestar suits teams that already use it and have conventions the agent can copy.
TestClient give the agent fast checks.For a broader comparison without the agent angle, see best Python backend frameworks. Python support in Encore is in beta, and you can sign up for access.
For a new JSON API, FastAPI is the strongest default, because its type hints double as validation and documentation, it is the most used Python web framework in the 2025 Stack Overflow survey, and its TestClient lets an agent test endpoints in-process. Django suits apps with a relational schema and an admin, because its conventions tell the agent where every piece goes. Encore is not a framework but an infrastructure SDK you add to whichever one you pick, so the agent can also declare the database and queues it needs and test them locally.
Both work well. Django gives Claude Code strong conventions, generated migrations and a built-in test runner, which keeps changes predictable in a large app. FastAPI has a smaller surface and type-hint-driven validation, which makes endpoint changes easy to check. Pick by the shape of the app rather than the agent.
Install the encore-dev package, await encore.start() in the FastAPI lifespan handler, and declare postgres.Database at module level. The agent runs encore run, which starts Postgres locally, applies the migrations and runs the app, so it can call its new endpoint and check the result before you review the change. A deploy then provisions the database in your own AWS or GCP account. Python support in Encore is in beta.
Deploy to your cloud on AWS and Google Cloud
without managing infrastructure
Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.