Three genuinely co-equal frameworks, which is why this takes the folder shape the frameworks index describes: FastAPI, Django and Flask are separate subjects, not three spellings of one.
~2,650 words across 3 notes. Built August 2026. [reference]. Replaces the scaffold that stood here.
The one idea: these three sit at different points on one axis — how much the framework decides for you. Django decides nearly everything; Flask decides almost nothing; FastAPI decides the request boundary and nothing else. Every other difference follows.
The three
| FastAPI | Django | Flask | |
|---|---|---|---|
| Model | ASGI, async | WSGI (ASGI partial) | WSGI, sync |
| Batteries | validation + DI + docs | everything | routing only |
| ORM | none (SQLAlchemy) | built in | none (extension) |
| Migrations | Alembic | built in, excellent | Flask-Migrate |
| Admin UI | none | its killer feature | extension |
| Validation | Pydantic, automatic | Forms / DRF serializers | your choice |
| OpenAPI | free | DRF, or add-on | add-on |
| Structure | your problem | prescribed (apps) | your problem |
| Learning curve | gentle | steep, wide | gentle, then unbounded |
Choosing
FastAPI — a new JSON API, especially I/O-heavy or ML-serving. The type-hints-as-contract model removes a whole category of drift between validation, docs and code.
Django — a full web application with users, an admin, a database and server-rendered pages. If you need a CRUD admin interface, this decision is already made; nothing else in any ecosystem comes close.
Flask — server-rendered HTML, small services, odd-shaped glue, or an existing Flask codebase.
The honest default for a new API in 2026 is FastAPI, and for a new full product with an admin it’s Django. Flask’s remaining strong case is templates and small things.
Reading order
- FastAPI — [Intermediate] — type hints as the runtime contract,
Depends(), Pydantic, and the blocking-call bug everybody ships - Django — [Intermediate] — apps, the ORM and migrations, the admin, DRF, and the N+1 problem
- Flask — [Intermediate] — blueprints, the application factory, and the context locals that explain “working outside of request context”
The things worth carrying
- In FastAPI,
async defwith a blocking call inside freezes every concurrent request. Use plaindefand let the threadpool handle it → FastAPI - Pydantic parses rather than validates — it’s where type hints stop being advisory and become enforcement → FastAPI
select_related/prefetch_related, or you have an N+1. Watch the query count on every page you build → Django- Read generated migrations before applying — a rename detected as drop-and-create is data loss → Django
- Django’s fat-model convention couples domain logic to persistence. Productive small, painful large → Django
- Use Flask’s application factory from the start, or your tests can’t configure the app → Flask
requestin Flask is a context-local proxy, not a global — which is why background threads raise → Flask- None of the three gives you a service layer. Layering is yours in all cases → structuring a backend
Read this first
Runtime & Concurrency Models, then the GIL note. The WSGI/ASGI split is the single most consequential difference here, and it decides how each of these scales, how you deploy it, and which libraries you’re allowed to use.
Where this connects
| languages/06-python/ | The language itself — the other half of this, per the rule |
| Express | Flask’s analogue; the same minimalist trade |
| Spring Boot | Django’s analogue; batteries and a container |
| structuring a backend | The layering none of these provide |
| databases | What the ORM generates, and why N+1 hurts |
| AI engineer | Why FastAPI dominates model serving |
The honest note
[reference] — no Python backend in this vault’s projects/; the backend work here is Node/Nest and Java/Spring. So the framework-shaped judgements are read, not earned, and that’s a real caveat on the “choosing” section above: the trade-offs are reported accurately, but I haven’t personally hit the wall each one describes.
What would close the gap:
- Build the same small API three times — one endpoint, one model, validation, tests. It’s a weekend, and the comparison table becomes something you know rather than something you read
- Ship the blocking bug on purpose.
async def+time.sleep(2), then load-test it withheyorwrk. Watch throughput collapse to serial. Nothing else makes note 01’s rule stick - Build a Django admin for something real. The claim that it’s the deciding feature is only checkable by using it
- Cause an N+1, find it with
django-debug-toolbar, fix it withselect_related, and record the query counts
What’s missing: deployment specifics (Docker, ASGI/WSGI server tuning, worker counts), Celery and background jobs, WebSockets and Django Channels, django-ninja, Litestar, auth implementation at depth, and testing each framework properly.
Related
- frameworks/ — the whole map
- Backend course — the concepts these implement
- Python
Software engineering
Infrastructure & security
Computer science
Hardware & engineering