Test-Driven Development with FastAPI and Docker

Learn how to build, test, and deploy a text summarization microservice with Python, FastAPI, and Docker!

Learning Objectives

By the end of this course, you will be able to:

  1. Develop an asynchronous RESTful API with Python and FastAPI
  2. Practice Test-Driven Development
  3. Test a FastAPI app with pytest
  4. Interact with a Postgres database asynchronously
  5. Containerize FastAPI and Postgres inside a Docker container
  6. Run unit and integration tests with code coverage inside a Docker container
  7. Check your code for any code quality issues via a linter
  8. Configure GitHub Actions for continuous integration and deployment
  9. Use GitHub Packages to store Docker Images
  10. Speed up a Docker-based CI build with Docker Cache
  11. Deploy FastAPI, Uvicorn, and Postgres to Heroku with Docker
  12. Parameterize test functions and mock functionality in tests with pytest
  13. Run tests in parallel with pytest-xdist
  14. Document a RESTful API with Swagger/OpenAPI
  15. Run a background process outside the request/response flow

Tools and Technologies


  1. Python
  2. FastAPI
  3. Docker
  4. Postgres
  5. Tortoise ORM
  6. Uvicorn
  7. Gunicorn

Testing and Linting

  1. pytest
  2. Coverage.py
  3. Flake8
  4. Black
  5. isort
  6. HTTPie


  1. GitHub Actions
  2. GitHub Packages
  3. Heroku
  4. Swagger/OpenAPI

fastapi tdd logo


This is not a beginner course. It's designed for the advanced-beginner -- someone with at least six months of web development experience. Before beginning, you should have some familiarity with the following topics. Refer to these resources for more info:

Topic Resource
Docker Get started with Docker
Docker Compose Get started with Docker Compose
FastAPI First Steps from the official FastAPI tutorial



  • Current version: 1.2.0
  • Last updated: March 15th, 2021
  • AuthorMichael Herman

What will you learn?

Part 1

In this first part, you'll learn how to develop an async RESTful API with Python, FastAPI, and Postgres. You'll containerize FastAPI and Postgres to run inside Docker containers and configure pytest in order to practice Test-Driven Development (TDD).

Part 2

In the second part, you'll start by deploying FastAPI, Gunicorn, Uvicorn, and Postgres to Heroku with Docker. You'll then continue to build out the RESTful API as you write unit and integration tests. Finally, we'll develop a text summarization service to produce article summaries from a given URL.

Table of Contents

Table of contents from Test-Driven Development with FastAPI and Docker:

Part 1
Part 2
  • Deployment
  • Code Coverage and Quality
  • Continuous Integration
  • Continuous Delivery
  • Remaining Routes
  • Pytest Monkeypatching
  • Text Summarization
  • Advanced CI
  • Workflow
  • Structure
  • Next Steps

Get the full course:

Join our mailing list to be notified about course updates and new tutorials.