<<Download>> Download Microsoft Word Course Outline Icon Word Version Download PDF Course Outline Icon PDF Version

Updated June 2026

Build REST APIs with Python and FastAPI

Class Duration

21 hours of live training delivered over 3-5 days to accommodate your scheduling needs.

Student Prerequisites

  • Experience with Python programming
  • Experience with REST APIs is recommended but not required

Target Audience

All students should be able to comfortably write Python scripts using basic data types, program structures, and the standard Python library. Teams preferring a different framework can compare Build REST APIs with Python and Flask and RestX.

Description

The Build REST APIs with Python and FastAPI training course is for students who have Python experience and desire to build REST APIs with Python. The course starts by covering the essential concepts of REST APIs, the HTTP protocol, and standard data formats such as JSON. Students then learn Pydantic v2 (with Annotated/Field patterns and discriminated unions), the data validation foundation that powers FastAPI, before building REST APIs with the FastAPI framework using lifespan events, the Annotated dependency syntax, BackgroundTasks, StreamingResponse / Server-Sent Events, and WebSockets. Since most REST APIs utilize databases, the class covers integrating async SQLAlchemy 2.0 (with Alembic migrations and eager-loading patterns) - PostgreSQL, SQL Server, or MongoDB available by client choice. The course also covers FastAPI's dependency injection system, middleware, and writing tests for FastAPI applications. Finally, topics such as security (JWT, OAuth2, and password hashing), GraphQL with Strawberry, and cloud deployment are covered.

Learning Outcomes

  • Understand the benefits and principles of a REST API and review how the HTTP protocol applies to REST APIs.
  • Use Pydantic v2 for data validation, serialization, and configuration, including Annotated/Field patterns and discriminated unions.
  • Connect to a Postgresql or SQL Server database with Python and integrate async SQLAlchemy 2.0 with Alembic migrations for database access.
  • Review Python Web Framework options and tools commonly used when developing REST APIs.
  • Build a REST API using the Python FastAPI REST API framework with lifespan events, BackgroundTasks, SSE, and WebSockets, using FastAPI's dependency injection system with the Annotated syntax.
  • Write tests for FastAPI applications including async transaction isolation and dependency overrides.
  • Secure REST APIs with JWT, OAuth2, CORS, and password hashing (Argon2/bcrypt).
  • Build GraphQL APIs with Strawberry.

Training Materials

Comprehensive courseware is distributed online at the start of class. All students receive a downloadable MP4 recording of the training.

Software Requirements

Students will need a free, personal GitHub account to access the courseware. Students will need permission to install Python and Visual Studio Code on their computers. Also, students will need permission to install Python Packages and Visual Studio Code extensions. If students are unable to configure a local environment, a cloud-based environment can be provided.

Training Topics

Development Environment (Very Quick Overview)

  • Configure VS Code for Python development
  • Code Reformatting with Black or Ruff
  • Debugging Python Scripts with VS Code
  • Running FastAPI Apps with fastapi dev and fastapi run

Quick Review of HTTP and URLs

  • What is HTTP?
  • What are HTTP Verbs?
  • What are the parts of a URL?
  • Path Parameters
  • Query String Parameters
  • Common HTTP Headers
  • Common HTTP Status Codes

Quick Review of Databases

  • What is a Database?
  • Connecting to a Database
  • Query data from a Database
  • Modify data in a Database

Overview of Python Web Frameworks

  • Django
  • Flask
  • FastAPI

Representational State Transfer

  • What is REST?
  • HTTP Verbs and their use in REST
  • OpenAPI
  • JSON
  • Swagger

Pydantic

  • BaseModel Fundamentals
  • Field Types and Constraints (Annotated + Field Patterns)
  • Custom Validators (field_validator and model_validator)
  • Nested Models
  • Discriminated Unions
  • Serialization and JSON Schema Generation
  • Pydantic v2 Features and model_config
  • Application Configuration with pydantic-settings

Building a REST API with FastAPI

  • Create an Application with the lifespan context manager (Replaces @app.on_event)
  • Define routes (path operations)
  • Path and query parameters with type hints using Annotated
  • Request body with Pydantic 2 models (validators, computed fields, model_config)
  • Response models and response_model_exclude_unset
  • Handling cookies and headers
  • Error handling and HTTPException
  • Specific status codes
  • Structured Error Response Models
  • Async routes (the FastAPI default)
  • BackgroundTasks for Fire-and-Forget Work
  • StreamingResponse, Server-Sent Events (SSE), and Streaming JSON Lines for Large Payloads
  • WebSockets (Introduction)
  • Pagination Patterns: Offset and Cursor
  • OpenAPI 3.1 docs (the FastAPI default since 0.99)
  • Serving static files

Dependency Injection

  • What is Dependency Injection?
  • Using the Annotated Dependency Syntax: Annotated[T, Depends(...)]
  • Class-Based Dependencies
  • Sub-Dependencies and Dependency Chains
  • Global and Router-Level Dependencies
  • Yield-Based Dependencies for Resource Management

Async SQLAlchemy and Pydantic Integration

  • Async SQLAlchemy 2.0 Setup with asyncpg
  • Defining ORM Models
  • Async Session Management via Depends() (with expire_on_commit=False, pool_pre_ping, and pool_recycle)
  • Separating Pydantic Schemas from ORM Models
  • Create, Read, and Update Schema Patterns
  • ORM-to-Pydantic Mapping with from_attributes
  • Eager Loading with selectinload to Avoid N+1 Queries
  • Implementing CRUD Operations in Async Routes
  • Schema Migrations with Alembic (Introduction)

Middleware

  • What is Middleware?
  • Creating Custom Middleware
  • Request and Response Processing
  • Built-in Middleware
  • Middleware Execution Order

Testing

  • pytest Fundamentals for API Testing
  • Testing Routes with FastAPI TestClient
  • Testing Async Endpoints with httpx AsyncClient
  • Overriding Dependencies in Tests
  • Database Fixtures and Test Isolation
  • Async Test Isolation with Transaction Rollback
  • Testing WebSockets and Streaming Endpoints

Security

  • Password Hashing with pwdlib (Argon2 default, bcrypt fallback) - replaces unmaintained passlib
  • Secure a REST API with JWT
  • OAuth2 Password Flow (Local Issuer Pattern; Legacy - Removed in OAuth 2.1)
  • Authorization Code + PKCE (The Production-Correct Pattern)
  • Refresh Tokens and Token Expiration Strategy
  • Configure CORS

GraphQL with Strawberry

  • What is GraphQL?
  • GraphQL vs REST: When to Use Each
  • Strawberry GraphQL Setup with FastAPI
  • Defining Schemas with Python Types
  • Queries and Resolvers
  • Mutations
  • DB-Backed Resolvers with Async SQLAlchemy
  • Error Handling in GraphQL

Cloud Deployment

  • Microservice Architecture
  • REST API Containerization
  • Running Server-Less in Azure
<<Download>> Download Microsoft Word Course Outline Icon Word Version Download PDF Course Outline Icon PDF Version