Learn FastAPI from Django¶
A personal, opinionated set of conspect notes for a Django developer moving to FastAPI. Every topic explains FastAPI on its own terms and then puts it side by side with Django, so years of Django experience transfer instead of getting in the way.
All material targets FastAPI 0.139, Django 6.0, and Python 3.13 (with Pydantic v2, Starlette, and Uvicorn as the FastAPI stack).
Who this is for¶
You know Django well — models and migrations, the ORM and QuerySet,
the admin, DRF serializers, class-based views, middleware, settings.py.
You do not know FastAPI yet. This book assumes exactly that: it never
explains what a migration is, but it explains every FastAPI, Starlette,
and Pydantic concept from zero, and each article ends by mapping it back
to what you already do in Django.
How the notes are organised¶
Each topic is a numbered folder. Inside each folder, conspects and
runnable examples share one numeric sequence so the reading order is
always obvious. The Django comparison lives in > **From Django:**
callouts and side-by-side code, not in a separate chapter.
Getting started¶
- What is FastAPI — the framework, the stack, and how its philosophy differs from Django's.
Planned topics¶
The structure below is the working outline for the book — it will grow into linked articles as each one is written.
- Getting started — what FastAPI is, installing it, your first app, the dev server (
uvicornvsrunserver), project layout without Django's app/project scaffolding, and application lifespan (startup/shutdown, theAppConfig.ready()analogue). - Routing and requests — path operations vs
urls.py, path and query parameters, request bodies, responses and status codes, error handling and exceptions (HTTPException, handlers, the422shape), forms and file uploads, and the shift away from class-based views. - Data with Pydantic — Pydantic models vs Django forms and DRF serializers, validation,
response_model, and settings (pydantic-settingsvssettings.py). - Templates and static files —
Jinja2Templatesvs the Django Template Language,render()→ returning anHTMLResponse, and serving static assets vscollectstatic. - Databases — SQLAlchemy + Alembic: models, the session, migrations vs Django migrations, querying, serializing ORM objects with Pydantic (
from_attributes, theModelSerializeranalogue), and async access. - Dependency injection —
Depends(), the idea Django has no direct equivalent for; dependencies withyield, sub-dependencies, reuse, and what replaces signals. - Authentication — Django auth/sessions vs OAuth2/JWT, security dependencies, CSRF and the cookie-vs-token model, and CORS.
- Middleware — Starlette middleware vs Django's
MIDDLEWAREstack. - Async and concurrency — WSGI vs ASGI,
async defand when to use it, background tasks vs Celery, and WebSockets vs Django Channels. - Testing — pytest:
TestClient, fixtures, and testing dependencies and async code. - The admin gap and deployment — what replaces
django.contrib.admin, and deploying Uvicorn workers.
Appendix — Ecosystem map: a Django-package → FastAPI-stack cheat-sheet (DRF → FastAPI-native, django-allauth → fastapi-users, Celery → arq/Celery, django.contrib.admin → SQLAdmin, django-filter → query params, caching, pagination, rate limiting, and packaging).
Companion projects¶
Every chapter ships with two small, runnable companion projects — one in FastAPI and one in Django — that implement exactly the functionality the chapter describes, with tests proving they work. You can read the chapter, then download and run both sides to see the same feature built each way.
Source¶
- Source repository: https://github.com/oduvan/learn-fastapi-from-django.
- Each conspect cites the official sources it consulted at the bottom of the page — typically fastapi.tiangolo.com, docs.pydantic.dev, starlette.io, and docs.djangoproject.com.