FastAPI, Django, Flask, Litestar and Starlette ranked for teams building Python backends that have to run in production, plus how to add the database and queues none of them provide.

The best Python backend frameworks in 2026 are FastAPI for new APIs, Django for apps that want an ORM, admin and auth included, and Flask for small services, with Litestar and Starlette as typed and minimal ASGI options. None of them provision a database or queue. Encore, in private beta for Python, adds that layer to whichever framework you pick.
The order follows adoption and fit for a new backend. In the 2024 Python Developers Survey from the PSF and JetBrains, FastAPI was used by 38% of respondents, up from 21% in 2021, ahead of Django at 35% and Flask at 34%. Versions are the latest releases on PyPI.
Verdict. Start a new API on FastAPI, pick Django when the app is mostly CRUD over a relational schema and someone needs an admin, and pick Flask only when the service is small and you want to choose every library yourself. Whichever you pick, pair it with Encore when you want the database, queues and cron jobs declared in the same codebase instead of in Docker Compose and Terraform.
What to weigh when choosing:
Pair the framework with Encore. It works alongside your framework: routing, validation and request handling stay in FastAPI, Django or Flask, while Postgres databases, Pub/Sub topics, buckets, cron jobs and secrets become module-level declarations in the same Python code. encore run starts the database, topics and buckets locally next to the app, and a deploy provisions the same declarations in your own AWS or GCP account. There is no Docker Compose file for local development and no Terraform for production.
Encore for Python is in private beta, and you can request an invite. Here is a FastAPI service with a database and a topic, the way the Python docs describe it:
# orders/main.py (FastAPI 0.165, Encore for Python private beta)
import os
from contextlib import asynccontextmanager
import encore
import uvicorn
from encore import pubsub
from encore.storage import postgres
from fastapi import FastAPI
from pydantic import BaseModel
# Local Postgres under `encore run`; RDS or Cloud SQL when deployed.
db = postgres.Database("orders", migrations="./migrations")
class OrderPlaced(BaseModel):
order_id: int
# Local broker under `encore run`; SNS/SQS or GCP Pub/Sub when deployed.
order_placed = pubsub.Topic[OrderPlaced]("order-placed")
async def send_receipt(message: pubsub.Message[OrderPlaced]) -> None:
print("sending receipt for order", message.data.order_id)
receipts = pubsub.Subscription[OrderPlaced](
order_placed, "send-receipt", handler=send_receipt
)
@asynccontextmanager
async def lifespan(app: FastAPI):
await encore.start() # starts the subscription handlers
yield
app = FastAPI(lifespan=lifespan)
class NewOrder(BaseModel):
total_cents: int
@app.post("/orders", status_code=201)
async def create_order(req: NewOrder) -> dict:
row = await db.query(
"INSERT INTO orders (total_cents) VALUES ($1) RETURNING id", req.total_cents
).one()
await order_placed.publish(OrderPlaced(order_id=row["id"]))
return {"id": row["id"]}
if __name__ == "__main__":
host, _, port = os.environ.get("ENCORE_LISTEN_ADDR", "0.0.0.0:8000").rpartition(":")
uvicorn.run(app, host=host, port=int(port))
ENCORE_LISTEN_ADDR.The service is registered with an encore.service.json file next to the code, and encore run applies the migration and delivers each published order to send_receipt. Cron jobs run where the app is deployed, not under encore run, so you call a job's endpoint directly to test it.
The same pattern holds for Django and Flask, since Encore never touches the routing. That also makes it a good fit for AI coding agents: the agent adds a topic or a bucket in the same change as the handler that uses it and runs it locally right away, without a Terraform module or a console step. For framework-specific code, see FastAPI vs Django vs Flask and Python microservices.
FastAPI builds on Starlette and Pydantic, and the parameters you declare become validated path, query and body inputs and an OpenAPI schema.
# fastapi 0.165
from fastapi import FastAPI
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}
Depends handles dependency injection for auth, database sessions and shared logic.FastAPI is an API framework, not an application framework, so the ORM, migrations tool, auth, background jobs and project layout are your choice, and larger codebases need conventions that the framework does not enforce. BackgroundTasks runs in the same process as the request, so long-running work that must survive a restart belongs in a queue.
When the app is mostly CRUD over a relational schema and someone needs an admin. Django ships an ORM, migrations, an admin interface, authentication, forms and templating, and most API work adds Django REST framework or django-ninja on top.
# models.py (Django 6.1)
from django.db import models
class User(models.Model):
email = models.EmailField(unique=True)
created_at = models.DateTimeField(auto_now_add=True)
Async views and parts of the async ORM exist, although much of the ecosystem is still sync-first, and the conventions that help large teams get in the way when you only need a few JSON endpoints.
Yes, for small services and internal tools: Flask gives you routing, request and response objects and templating, and everything else comes from extensions.
# flask 3.1
from flask import Flask, request
app = Flask(__name__)
@app.post("/users")
def create_user():
data = request.get_json()
return {"email": data["email"]}, 201
Flask is WSGI and synchronous by default, with no built-in validation, and the project structure is up to you, so most new async JSON APIs start on FastAPI instead.
For teams that want more built in, it can be. Litestar is an ASGI framework with typed route handlers, dependency injection and generated OpenAPI docs, and it includes a SQLAlchemy plugin and DTOs for shaping data, which FastAPI leaves to you.
# litestar 2.25
from litestar import Litestar, post
from msgspec import Struct
class Signup(Struct):
email: str
@post("/users")
async def create_user(data: Signup) -> dict:
return {"email": data.email}
app = Litestar(route_handlers=[create_user])
Its community and third-party ecosystem are smaller, so there are fewer tutorials, integrations and published examples than for FastAPI.
StarletteWhen the service is small and has little input to validate. Starlette is the ASGI toolkit FastAPI is built on, with routing, middleware, WebSockets and background tasks but no validation layer.
# starlette 1.10
from starlette.applications import Starlette
from starlette.responses import JSONResponse
from starlette.routing import Route
async def health(request):
return JSONResponse({"ok": True})
app = Starlette(routes=[Route("/health", health)])
Starlette works well for small services, proxies and custom framework layers. Anything that takes request bodies ends up with validation code that FastAPI would have provided.
Whichever framework you pick, the database, queue, bucket and cron schedule still have to exist locally, in preview environments and in production. Encore for Python is in private beta, and you can request an invite to declare that infrastructure in the framework app you already have.
FastAPI for new JSON APIs, Django for apps that want an ORM, admin and auth included, and Flask for small services where the team wants to choose every library. Litestar suits typed async APIs that want more built in than FastAPI, and Starlette is the minimal ASGI toolkit FastAPI is built on. In the 2024 Python Developers Survey, FastAPI was used by 38% of respondents, Django by 35% and Flask by 34%.
Use Django when you want a full application framework with an ORM, migrations, admin and auth included. Use FastAPI when you are building an API, want async handlers with type-hint-driven validation, and are fine choosing your own ORM and auth.
Yes. Flask is a good fit for small services and internal tools. It is synchronous by default and leaves structure, validation and data access to extensions you choose, so larger async APIs usually start on FastAPI instead.
No. FastAPI, Django, Flask, Litestar and Starlette handle requests, and the Postgres database, queue and bucket come from Docker Compose locally and Terraform or a console in production. Encore adds that layer to the framework you already use: you declare the resources in Python, encore run starts them locally, and a deploy provisions them in your own AWS or GCP account. Encore for Python is in private 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.