Test-Driven Development with FastAPI and Docker

  • Updated January 26th, 2024
  • v1.4.0
Michael Herman Michael Herman

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


In this course, you'll learn how to build, test, and deploy a text summarization service with Python, FastAPI, and Docker. The service itself will be exposed via a RESTful API and deployed to Heroku with Docker.

Various logos sitting around an Octopus

What will you learn?

Select a Part

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).

Learning Objectives

  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
  7. Check your code for any code quality issues via a linter

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.

Learning Objectives

  1. Configure GitHub Actions for continuous integration and deployment
  2. Use GitHub Packages to store Docker Images
  3. Speed up a Docker-based CI build with Docker Cache
  4. Deploy FastAPI, Uvicorn, and Postgres to Heroku with Docker
  5. Parameterize test functions and mock functionality in tests with pytest
  6. Run tests in parallel with pytest-xdist
  7. Document a RESTful API with Swagger/OpenAPI
  8. Run a background process outside the request/response flow

What do you need to know?

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:

FastAPI

Meet the Author

Michael Herman

Michael Herman

Michael is a software engineer and educator who lives and works in the Denver/Boulder area. He is the co-founder/author of Real Python. Besides development, he enjoys building financial models, tech writing, content marketing, and teaching.

What developers are saying

Test-Driven Development with FastAPI and Docker is a great course. We're using almost the exact same stack at work for a new project, so the course has provided me with a lot of immediate value. It's hard to find resources like it that cleanly bring in all of the working pieces without dragging on forever.

The Test-Driven Development with FastAPI and Docker course sets the foundations on how to develop a robust application by using test-driven design. It condenses in one resource what you can find in bits and pieces scattered around the web. The advantages of taking this course are that you don't have to glue several pieces together but you can have a cohesive view of the project. Recommended for people who don't want to waste time and start coding right away with solid foundations.

I'm coming from a Data Science background where my head is in Jupyter Notebooks 80% of the time. Test-Driven Development with FastAPI and Docker demystified many aspects of building the backend of a web app while ticking off several other milestones from my learning to-dos. As a long-time Docker user, I've wanted to learn Docker Compose -- check. A Github Actions admirer, thinking someday I'll learn that -- check. Continuous integration, continuous deployment, extensive testing, and coverage, -- check, check, check, check!

What's surprising is I've been down this path before with longer tutorials from other sites. For whatever reason, I would end up with the demo project but have no real clue about what I was doing. The TestDriven.io course is different. I feel confident in my ability to design an application start to finish.

A final side-note: I appreciate that the website adds versions and dates to their tutorials!! This is huge! There's nothing quite like finding the perfect tutorial that is not up-to-date. It's never fun to have to play detective before getting started.

Great job, Michael. I highly recommend this course and, by extension, this site.

The Test-Driven Development with FastAPI and Docker course has really nice pacing and progression. I'm grateful to be able to learn about FastAPI with Docker as well as TDD since it's been intimidating for me.

I am very much into buying and purchasing any course by you and your team. I've never felt like a better programmer ready to show my coding chops to the world.

Frequently Asked Questions

What tools and technologies are used in this course?

This course covers a variety of technologies and services:

Core

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

Testing and Linting

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

Services

  1. GitHub Actions
  2. GitHub Packages
  3. Heroku

What support does TestDriven.io offer?

Since the courses mimic real-world development, support is provided via Stack Overflow. Helpful users, including the developers of the courses, read and respond to messages on Stack Overflow. If you get stuck and you can't find an answer via Stack Overflow, feel free to reach out via email directly. Just be sure to detail what you've tried. For more, review Support and Consulting.

How long does it take to complete the course?

It's dependent on your current skill level. On average, it takes approximately 10 hours to complete.