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. Pytest
  7. Uvicorn
  8. Coverage.py
  9. flake8
  10. Black
  11. isort
  12. HTTPie
  13. GitHub Actions
  14. GitHub Packages
  15. Gunicorn
  16. Heroku
  17. Swagger/OpenAPI

fastapi tdd logo

Prerequisites

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

Demo

Info

  • Current version: 1.0.0
  • Last updated: June 2nd, 2020
  • 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.