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:
- Develop an asynchronous RESTful API with Python and FastAPI
- Practice Test-Driven Development
- Test a FastAPI app with pytest
- Interact with a Postgres database asynchronously
- Containerize FastAPI and Postgres inside a Docker container
- Run unit and integration tests with code coverage inside a Docker container
- Check your code for any code quality issues via a linter
- Configure GitHub Actions for continuous integration and deployment
- Use GitHub Packages to store Docker Images
- Speed up a Docker-based CI build with Docker Cache
- Deploy FastAPI, Uvicorn, and Postgres to Heroku with Docker
- Parameterize test functions and mock functionality in tests with pytest
- Run tests in parallel with pytest-xdist
- Document a RESTful API with Swagger/OpenAPI
- Run a background process outside the request/response flow
Tools and Technologies
Core
- Python
- FastAPI
- Docker
- Postgres
- Tortoise ORM
- Uvicorn
- Gunicorn
Testing and Linting
- pytest
- Coverage.py
- Flake8
- Black
- isort
- HTTPie
Services
- GitHub Actions
- GitHub Packages
- Heroku
- Swagger/OpenAPI
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.1.0
- Last updated: December 16th, 2020
- Author: Michael 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
- Introduction
- Changelog
- Getting Started
- Docker Config
- Postgres Setup
- Pytest Setup
- App Structure
- RESTful Routes
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.