Books

Best Django, Flask and FastAPI Books (2026): 11 Picks Ranked

This post contains affiliate links. If you buy through them, we may earn a small commission at no extra cost to you. Learn more.

Choosing a Django, Flask or FastAPI book comes down to one question: will its code still run on the framework you install today? Django is on 6.1. FastAPI moved to Pydantic 2 back in 2023, and a book with a 2023 requirements file can break before you reach chapter 3. You’ll want the book whose examples match the stack you’re about to deploy.

Original content from computingforgeeks.com - post 183185

We shortlisted 11 current Python web development books, four for Django, three built on Flask, and four for FastAPI, then cloned the companion repositories and ran tests, system checks or example scripts against current releases. Ten of the 11 got a code run, and the results decide most of the rankings below. This list sits under our best programming books hub, alongside the general Python books round-up. Prices and stock below were checked against Amazon US in November 2026, the same week as the code runs.

Which Django, Flask or FastAPI book should you buy first?

For most people starting with Django, buy Django for Beginners, 6th Edition. It is the only Django book on this list whose code already pins Django 6.1, and all 25 of its newspaper project tests passed on the first run. If you’re on another framework, or past the beginner stage, start from what you need to ship:

The two Pydantic 1 era books, Microservice APIs and the second edition of Building Data Science Applications with FastAPI, are still worth reading for their design chapters. Just expect to pin old versions or patch code before their examples run, which we cover in each pick.

How we picked and tested the 11 books

Every pick had to teach Django, Flask or FastAPI as its main subject (Architecture Patterns with Python is the one exception, kept because its whole example app runs on Flask), be in print and buyable new on Amazon US, and publish its example code in a public repository. Popular older titles that fail the edition test were left out. The newest print Two Scoops of Django on Amazon covers Django 1.11, and Flask Web Development’s second edition repository pins Flask 0.12.2, which the 2024 Mega-Tutorial by the same author replaces. Each pick then went through the same checks:

  • Edition: the cover, ISBN and Amazon listing all match the newest printing, confirmed through the Amazon catalog API.
  • Coverage: what we say each book teaches comes from the publisher page, the author site or the chapter folders in the book’s repository.
  • Code run: each repository went into its own virtual environment, installed from the requirements file that ships with the book, then ran again on current releases where the pins were old.

The test machine was an Ubuntu 24.04 VM with its stock Python 3.12, which is the oldest Python that Django 6 accepts. That makes it a fair stand-in for the server you will most likely deploy to. The capture below shows the framework releases every “current” run used:

Python 3.12 with Django 6.1.2, Flask 3.1.3, FastAPI 0.162.0 and Pydantic 2.14.2 installed on Ubuntu 24.04

Django 6.1.2 is the latest release, while 5.2 is still the long-term support line, per the Django download page. One book got no code run at all: Mastering Flask Web and API Development needs a PostgreSQL server loaded with a database dump from the author before its first chapter starts, so we judged it on its published contents instead. Prices are bands from the Amazon catalog on the day we checked, because book prices move weekly.

Django, Flask and FastAPI books compared

The table lines up all 11 picks. “Pinned to” is what the requirements file in the book repository installs, and the last column is what happened when we ran that code on the current release of its framework.

BookFrameworkEdition, yearPagesPinned toOn current release
Django for BeginnersDjango6th, 2026433Django 6.1.225 tests pass
Django for APIsDjango, DRF5th, 2025216Django 5.1Runs on pins and 6.1
Web Development with Django 6Django3rd, 2026758Django 6.0Needs DRF upgrade
Django 5 By ExampleDjango5th, 2024820Django 5.2 LTSChapter 1 runs clean
The Flask Mega-TutorialFlask2024 edition326Flask 3.0.04 tests pass
Mastering Flask Web and API DevelopmentFlask1st, 2024494Flask 3.xNot run
Architecture Patterns with PythonFlask1st, 2020304SQLAlchemy below 220 unit tests pass
FastAPI: Modern Python Web DevelopmentFastAPI1st, 2023277Unpinned71 tests pass, warnings
Building Data Science Applications with FastAPIFastAPI2nd, 2023422Pydantic 1.10.92 of 164 fail
Building Generative AI Services with FastAPIFastAPI1st, 2025528FastAPI 0.115.6Chapter 5 examples run
Microservice APIsFastAPI, Flask1st, 2023440Pydantic 1.9.1Fails until repinned

Read the last two columns together, because they tell you how much fixing you will do before the examples run. Django books age well, since Django keeps deprecated features working with warnings across at least two feature releases, and the only Django break we hit came from a third-party package, not Django itself. FastAPI books age by Pydantic generation: anything written for Pydantic 1 needs work, and anything from late 2023 onward runs with deprecation warnings at worst. Flask sits in between, and its plain WSGI core barely moved.

1. Django for Beginners (6th Edition)

William S. Vincent wins the Django beginner slot for you because this is the only book here already rewritten for Django 6.1.

Django for Beginners 6th Edition by William S. Vincent book cover
Django for Beginners, 6th Edition by William S. Vincent. Image: LearnDjango.

The 18 chapters build six projects of rising size, from a hello world page to a newspaper site with custom users, password reset, permissions and comments, then finish on performance, deployment and a short web API chapter. The repository has one folder per chapter, and every requirements file pins Django 6.1.2, so what you type matches what the book prints. We ran the chapter 15 newspaper project, the largest one in the book:

Django for Beginners 6th Edition chapter 15 newspaper project passing 25 tests on Django 6.1.2

All 25 tests passed and the system check reported no issues, which is as clean as you will see from a book repository. Install from the chapter’s requirements file rather than a bare Django install, because the newspaper project also needs django-crispy-forms and crispy-bootstrap5. Where it falls short:

  • No async views: the book stays with classic synchronous Django throughout.
  • APIs get one chapter: for Django REST Framework in depth you’ll want the next pick.
  • Price: about $50 for a 433-page self-published paperback is high for a beginner title.

Pick it if Django is your first Python web framework, or if you learned Django 3 or 4 and want a fast refresh on current idioms. Readers who’d rather install Django by hand first can follow our Django install guide for Fedora and then switch to the book at chapter 2.

2. Django for APIs (5th Edition)

Vincent’s API book is the shortest route from plain Django to a token-authenticated REST API, and it is the right second book after the first pick.

Django for APIs 5th Edition by William S. Vincent book cover
Django for APIs, 5th Edition by William S. Vincent. Image: Still River Press.

It builds a library API, a todo API with a separate front end, then a blog API that gains permissions, user authentication, viewsets and routers, and finally schema documentation. At 216 pages it moves fast, and you have a working library API by chapter 4. The catch is the date: the 2025 code pins Django 5.1.6 and Django REST Framework 3.15.2, three feature releases behind Django 6.1. We ran the chapter 10 blog API on its pins, upgraded Django, DRF, dj-rest-auth and django-allauth to current releases, then logged in and posted through the API:

Django for APIs 5th Edition blog API returning posts with dj-rest-auth token authentication on Django 6.1.2

The login endpoint returned a token, the POST created a post, and the list endpoint returned it, all on Django 6.1.2. Its one test passed before and after the upgrade too. That single test is the weak spot: the book teaches API testing thinly, so add your own tests before you trust a viewset change. Pick it if you know basic Django and need a working DRF API this month; pass on it if you only build APIs, because FastAPI books below cover more ground per page.

3. Web Development with Django 6 (Third Edition)

This Packt title is the one to buy if you want Django 6 covered in one thick volume, async views and all.

Web Development with Django 6 Third Edition by Guest, Walker, Shaw, Badhwar and Chandra K S book cover
Web Development with Django 6, Third Edition by Chris Guest, Mark Walker, Ben Shaw, Saurabh Badhwar and Bharath Chandra K S. Image: Packt.

Five authors carry one case study, Bookr, a book review site, through 18 chapters covering models, forms, Django 6 form rendering, sessions, authentication, async views and the async ORM, and a REST API. The March 2026 repository pins Django 6.0 and DRF 3.16.1. In the chapter 15 code, the last chapter the repository covers, that pin is exactly what broke once we moved to Django 6.1:

Web Development with Django 6 Bookr project failing with cc_delim_re ImportError on Django 6.1 until djangorestframework is upgraded

DRF 3.16.1 imports cc_delim_re from django.utils.cache, which Django 6.1 no longer has, so every management command dies with an ImportError. Upgrading DRF to 3.18.3 fixed it and the four review tests passed. The one remaining system check issue is a missing static folder warning, not an error. You will need two more setup steps on a fresh server:

  • A .env file: settings read SECRET_KEY, ENVIRONMENT and ALLOWED_HOSTS through python-decouple and refuse to start without them.
  • Pango libraries: the PDF export uses WeasyPrint, which failed with cannot load library 'libpango-1.0-0' on a minimal Ubuntu server until we installed the system packages.

Pick it if you like one long project and want async Django explained against Django 6. Pass on it if you want a slim book, because 758 pages of case study is slower going than Vincent’s two titles together.

4. Django 5 By Example (Fifth Edition)

Antonio Melé’s book is the best project book for Django once the basics are done, and the current printing targets Django 5.2 LTS.

Django 5 By Example Fifth Edition by Antonio Mele book cover
Django 5 By Example, Fifth Edition by Antonio Melé. Image: Packt.

Four full projects fill 820 pages: a blog, a social bookmarking site, an online shop with payments, and an e-learning platform. Each chapter folder in the repository ships its own requirements file and Docker setup, and the chapter 1 pins resolve to Django 5.2.18. We ran that blog on its pins, then moved it to Django 6.1.2:

Django 5 By Example chapter 1 blog project passing system checks on Django 5.2.18 and Django 6.1.2

Both versions passed the system check and Django found no model changes to migrate, so you can follow the 5.2 code on Django 6.1. We only ran chapter 1; later chapters pull in Celery, Redis and payment libraries, and those packages are where version drift usually bites. A sixth edition, Django 6 By Example, is listed for December 9, 2026 as a Kindle preorder, with no print date listed yet. Buy the fifth edition now if you want paper and want to start this month; if you read on Kindle and can wait five weeks, wait.

5. The New and Improved Flask Mega-Tutorial (2024 Edition)

Miguel Grinberg’s Mega-Tutorial is the Flask book to start with, and its code survived every upgrade we threw at it.

The New and Improved Flask Mega-Tutorial 2024 Edition by Miguel Grinberg book cover
The New and Improved Flask Mega-Tutorial, 2024 Edition by Miguel Grinberg. Image: Miguel Grinberg.

One app, a Twitter-style microblog, grows across the book from a single route to user logins, SQLAlchemy 2 models with Flask-Migrate, email, translations, full-text search, background jobs, an API and Docker deployment. The full text is also free on his blog, so the paperback is for reading away from a screen. The microblog repository pins Flask 3.0.0 and SQLAlchemy 2.0.23, so we ran its tests on the pins and again after upgrading:

Flask Mega-Tutorial microblog unit tests passing on Flask 3.0.0 pins and after upgrading to Flask 3.1.3 and SQLAlchemy 2.1

Four tests passed on both, including the jump to SQLAlchemy 2.1.6, so you can install current Flask and follow along. Four is a small suite, but it covers the user model, the password hashing and the follow logic the rest of the app leans on. The weakness is the format: it teaches by building one app from start to finish, so it is a poor desk reference when you need one topic fast. Pick it if Flask is your framework and you learn by building; it’s the clearest Flask writing in print.

6. Mastering Flask Web and API Development

Sherwin John C. Tragura’s book is the Flask title for people who already know Flask and need its enterprise integrations in one place.

Mastering Flask Web and API Development by Sherwin John C. Tragura book cover
Mastering Flask Web and API Development by Sherwin John C. Tragura. Image: Packt.

It’s written for Flask 3 and covers blueprints, SQL and NoSQL backends, REST APIs with JWT, role-based security with LDAP, OAuth and OpenID, async support in Flask, and background work with Celery and RabbitMQ. The final chapters connect Flask to React and Flutter front ends and to other services. Our run stopped at setup: the chapter 1 project connects to PostgreSQL through environment variables and expects a database dump from the author, so it is the only pick here with no code result.

  • Breadth: it covers more integrations than any other Flask book on this list.
  • Setup cost: most chapters assume a database server, so you cannot read it on a laptop with nothing installed.

Pick it when your company’s Flask app needs LDAP or OAuth bolted on and you want worked examples. Pass on it as a first Flask book, since the Mega-Tutorial explains the basics far more gently.

7. Architecture Patterns with Python

Harry Percival and Bob Gregory wrote the book that turns a working Flask app into one you can still change in two years.

Architecture Patterns with Python by Harry Percival and Bob Gregory book cover
Architecture Patterns with Python by Harry J.W. Percival and Bob Gregory. Image: O’Reilly Media.

It isn’t a Flask tutorial; Flask is just the thin entry point around a domain model, a repository, a service layer, a unit of work, events and a message bus, and CQRS. The book is free to read at cosmicpython.com. Its repository caps SQLAlchemy below 2, so pip installed 1.4.54, and the tests cannot import the app until you install the src package the way the Dockerfile does:

Architecture Patterns with Python companion code passing 20 unit tests with Flask 3.1.3 and SQLAlchemy 1.4

All 20 unit tests passed in 0.06 seconds with Flask 3.1.3. The integration and end-to-end suites need the Docker Compose stack with PostgreSQL and Redis, which we didn’t run. The ideas have not aged, but the SQLAlchemy 1.4 mapping style has, so expect to translate the ORM chapters if your project is on SQLAlchemy 2. Pick it once you’ve shipped one Flask or FastAPI service and it’s starting to hurt; the same patterns apply to both.

8. FastAPI: Modern Python Web Development

Bill Lubanovic’s book is the best first FastAPI book, and its code was the cleanest FastAPI run we had.

FastAPI Modern Python Web Development by Bill Lubanovic book cover
FastAPI: Modern Python Web Development by Bill Lubanovic. Image: O’Reilly Media.

It starts with the modern Python FastAPI relies on, type hints, async and Pydantic, then builds a small site in web, service and data layers backed by SQLite, with tests for each layer. The repository has no requirements file, so we installed FastAPI, Uvicorn, pytest and the auth libraries the code imports, then ran the unit tests:

FastAPI Modern Python Web Development companion code passing 71 unit tests on FastAPI 0.162 with Pydantic dict deprecation warnings

71 passed, with 11 warnings, and the visible ones come from .dict(), which Pydantic 2 deprecates in favour of model_dump(). You also get a running app: it started under Uvicorn and served its explorer endpoint and the /docs page with HTTP 200. Those warnings are the honest cost of a 2023 book: the code works, but you’ll learn a few names that newer docs replaced. Pick it as your first FastAPI book; pass on it if you need SQLAlchemy or PostgreSQL patterns, because the project uses raw SQLite and SQLAlchemy gets only a short chapter.

9. Building Data Science Applications with FastAPI (Second Edition)

François Voron’s book is the strongest FastAPI book on testing, but its requirements file is the most dated on this list.

Building Data Science Applications with FastAPI Second Edition by Francois Voron book cover
Building Data Science Applications with FastAPI, Second Edition by François Voron. Image: Packt.

Voron maintains FastAPI Users, and it shows: the chapters on dependencies, authentication, databases and testing are thorough, and the repository ships a test file per chapter. The later chapters serve scikit-learn models, run object detection and generate images with Stable Diffusion. The root requirements file pins FastAPI 0.96.0 and Pydantic 1.10.9 from mid 2023, and on Python 3.12 it doesn’t install at all:

Building Data Science Applications with FastAPI requirements failing on Python 3.12 numpy build, chapter tests passing on pins and two failing on Pydantic 2

The pinned numpy 1.24.3 has no Python 3.12 wheel, so pip builds it from source and hits the removed distutils module. Installing just the web stack at the pinned versions, plus test tools from that era, got 164 of 164 chapter 3 to 5 tests passing. On FastAPI 0.162 and Pydantic 2.14.2, 162 still passed. One failure is Pydantic 2 refusing a bare @root_validator, the other a request that now returns 422 instead of 200. Pick it if you serve models through FastAPI and can work in a Python 3.11 environment; pass on it if you want copy-paste code on today’s stack.

10. Building Generative AI Services with FastAPI

Alireza Parandeh’s 2025 book is the newest FastAPI title we found, and the only one built around serving language and image models.

Building Generative AI Services with FastAPI by Alireza Parandeh book cover
Building Generative AI Services with FastAPI by Alireza Parandeh. Image: O’Reilly Media.

Its 528 pages cover loading Hugging Face models inside FastAPI, calling the OpenAI API, streaming responses, retrieval with the Qdrant vector store, caching and rate limiting. The repository keeps a start and end branch per chapter and pins FastAPI 0.115.6 with Pydantic 2, so it is already on the current Pydantic generation. Most chapters need PyTorch and multi-gigabyte model downloads, so on our small CPU-only VM we ran the chapter 5 concurrency examples that explain why the book uses async at all:

Building Generative AI Services with FastAPI chapter 5 sync example taking 15 seconds and asyncio example taking 5 seconds

Three blocking five-second tasks took 15.0 seconds, while the same three under asyncio.gather took 5.0. That is the lesson behind every streaming endpoint later in the book. Its README asks for Python 3.11 and the full requirements file is heavy, so you are better off with a separate environment, ideally with a GPU. Pick it if your API exists to serve a model; for LLM theory rather than serving, our LLM engineering books list goes deeper.

11. Microservice APIs

José Haro Peralta’s Manning book is about API design first and framework second, which is why it still earns a place despite the broken code.

Microservice APIs Using Python, Flask, FastAPI by Jose Haro Peralta book cover
Microservice APIs: Using Python, Flask, FastAPI, OpenAPI and More by José Haro Peralta. Image: Manning.

It designs a coffee shop’s services contract first with OpenAPI, builds the orders API in FastAPI and the kitchen API in Flask, then adds GraphQL, authorization and deployment. The chapter 2 orders API failed twice before it ran:

Microservice APIs chapter 2 orders API failing on Pydantic 2 and on the book's Pydantic 1.9.1 lock, then running with Pydantic 1.10

On current FastAPI, Pydantic 2 rejects conlist(..., min_items=1) because the argument is now min_length. The lock file in the repository, FastAPI 0.79.0 with Pydantic 1.9.1, fails differently on Python 3.12 with 'not' is not a valid parameter name. Keeping FastAPI 0.79.0 and moving Pydantic to the last 1.10 release fixed it, and the POST created the order and returned it with an ID and a “created” status. Pick it for the OpenAPI and API design chapters; pass on it if you want code that runs as printed. Amazon showed it shipping with a lead time rather than in stock when we checked, so you may wait a few days for a copy.

What breaks when you run older Python web book code

Four of our ten runs needed a fix before they worked, and the fixes fell into a short list of causes. Knowing them lets you buy an older book with your eyes open:

  • Pydantic 1 code on Pydantic 2: renamed arguments such as min_items and stricter validators break the FastAPI books you’ll find from before mid 2023.
  • Old pins on Python 3.12: numpy 1.24 and Pydantic 1.9 don’t install or import on 3.12, and Django 6 won’t run on anything older.
  • Third-party packages behind Django: DRF 3.16 broke on Django 6.1 while Django itself raised nothing.
  • System libraries: WeasyPrint and other C-backed packages need distro packages that pip can’t install.
  • Packaging steps: src-layout projects need pip install -e before their tests can import the app.

Each fix you will need is one command. Upgrading the package that sits between the book and the framework solved the Django break:

pip install --upgrade djangorestframework

For a Pydantic 1 book that you’d rather run as printed, keep the FastAPI version the book pins and take the last Pydantic 1 release, which supports Python 3.12. Current FastAPI requires Pydantic 2. So the FastAPI pin goes in the same command. Here it’s 0.79.0, the Microservice APIs pin:

pip install "fastapi==0.79.0" "pydantic>=1.10.13,<2"

On Ubuntu or Debian, WeasyPrint’s missing libraries come from the distro, not PyPI. We installed the two Pango packages. That got the app importing. The WeasyPrint docs also list two HarfBuzz packages for real PDF output:

sudo apt-get update && sudo apt-get install -y libpango-1.0-0 libpangoft2-1.0-0 libharfbuzz0b libharfbuzz-subset0

The longer-term fix is to port the code. Pydantic publishes a version 2 migration guide that maps every renamed method and argument, and working through it on a book’s examples is decent practice in itself. If the data layer is where you get stuck, our PostgreSQL books cover the database side these web books skim.

Reading order for each framework

One book rarely covers a framework end to end. These are the orders we’d follow if you’re starting from zero and want each book to build on the one before it:

  1. Django: Django for Beginners, then Django for APIs or Django 5 By Example depending on whether you’re building an API or a site, then Architecture Patterns with Python.
  2. Flask: the Mega-Tutorial, then Architecture Patterns with Python, and Mastering Flask Web and API Development only when you need its integrations.
  3. FastAPI: FastAPI: Modern Python Web Development, then Building Generative AI Services with FastAPI if you serve models, or Microservice APIs if you design many services.

Whichever path you take, run the code from each book in its own virtual environment with the pinned requirements file first, then upgrade one package at a time. That’s how every failure above showed itself as a single named package rather than a wall of tracebacks. When the services are ready to ship, the Docker books and system design books pick up where these leave off.

Keep reading

Best Machine Learning Books (2026): Textbooks, Python, Free PDFs AI Best Machine Learning Books (2026): Textbooks, Python, Free PDFs Best C++ and C Programming Books for 2026: Beginner to Advanced Books Best C++ and C Programming Books for 2026: Beginner to Advanced Best System Design Books for Interviews and Architecture in 2026 Books Best System Design Books for Interviews and Architecture in 2026 Best OpenShift Books for Admins and EX280 Candidates Books Best OpenShift Books for Admins and EX280 Candidates Best API Design Books: REST, gRPC and GraphQL Books Best API Design Books: REST, gRPC and GraphQL Best DevSecOps Books for 2026 Books Best DevSecOps Books for 2026

Leave a Comment

Press ESC to close