Outline updated November 2026

Foundation21 hours delivered over 3-5 daysLive, online or on-site

Request this course

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

  • Comfortable writing Python scripts with basic data types, program structures, and the standard library
  • Experience with REST APIs is recommended but not required

Target Audience

Python developers and backend engineers who build REST APIs and web services. New to Python? Start with Introduction to Python. Teams moving existing Flask or Flask-RESTX services to FastAPI should also see Migrating Flask APIs to FastAPI.

Description

This course is for Python developers who want to build REST APIs with FastAPI. It starts with REST concepts, the HTTP protocol, and JSON. Students then learn Pydantic, the validation library under FastAPI, and build APIs with dependency injection, background tasks, streaming, and WebSockets. Database modules cover async SQLAlchemy and Alembic, with PostgreSQL or SQL Server by client choice. The course ends with testing, security with JWT and OAuth2, GraphQL with Strawberry, and cloud deployment.

Learning Outcomes

  • Explain REST principles and how HTTP applies to them.
  • Validate and serialize data with Pydantic models.
  • Load application settings with pydantic-settings.
  • Compare Python web frameworks for API work.
  • Build REST APIs with FastAPI path operations and dependency injection.
  • Stream responses with Server-Sent Events and WebSockets.
  • Write custom middleware for request and response processing.
  • Access PostgreSQL or SQL Server with async SQLAlchemy.
  • Manage schema changes with Alembic migrations.
  • Test FastAPI apps with dependency overrides and transaction rollback.
  • Secure APIs with JWT, OAuth2, CORS, and password hashing.
  • Build GraphQL APIs with Strawberry.

Training Materials

Comprehensive courseware is distributed online at the start of class.

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. Examples use Python 3.11 or later, FastAPI, Pydantic 2, and SQLAlchemy 2.x. 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 formatting with Black or Ruff
  • Debugging Python scripts with VS Code
  • Running 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
  • Querying data
  • Modifying data

Overview of Python Web Frameworks

  • Django
  • Flask
  • FastAPI

Representational State Transfer

  • What is REST?
  • HTTP verbs in REST
  • OpenAPI
  • JSON
  • Swagger

Pydantic

  • BaseModel fundamentals
  • Field types and constraints
  • Annotated and Field patterns
  • Custom validators
  • field_validator and model_validator
  • Nested models
  • Discriminated unions
  • Serialization and JSON Schema generation
  • Model configuration with model_config
  • Application settings with pydantic-settings

Building a REST API with FastAPI

  • Startup and shutdown with lifespan
  • Defining path operations
  • Path and query parameters with Annotated
  • Request bodies with Pydantic models
  • Computed fields
  • Response models
  • Handling cookies and headers
  • Error handling and HTTPException
  • Custom status codes
  • Structured error response models
  • Async routes with async def
  • Background tasks
  • Streaming responses
  • Server-Sent Events
  • Streaming JSON Lines
  • Introduction to WebSockets
  • Offset and cursor pagination
  • OpenAPI docs with Swagger UI and ReDoc
  • Serving static files

Dependency Injection

  • What is dependency injection?
  • Using Depends with Annotated
  • Class-based dependencies
  • Sub-dependencies and dependency chains
  • Global and router-level dependencies
  • Dependencies with yield

Async SQLAlchemy and Pydantic Integration

  • Async SQLAlchemy setup with asyncpg
  • Defining ORM models
  • Async session dependencies
  • expire_on_commit and pool settings
  • Separating Pydantic schemas from ORM models
  • Create, read, and update schema patterns
  • Mapping ORM objects with from_attributes
  • Eager loading with selectinload
  • Avoiding N+1 queries
  • CRUD operations in async routes
  • Introduction to Alembic migrations

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
  • Transaction rollback for async test isolation
  • Testing WebSockets and streaming endpoints

Security

  • Password hashing with pwdlib and Argon2
  • Securing a REST API with JWT
  • The OAuth2 password flow and its limits
  • Authorization code flow with PKCE
  • Refresh tokens and expiration
  • Configuring CORS

GraphQL with Strawberry

  • What is GraphQL?
  • Choosing GraphQL or REST
  • Strawberry setup with FastAPI
  • Defining schemas with Python types
  • Queries and resolvers
  • Mutations
  • Database-backed resolvers with async SQLAlchemy
  • Error handling in GraphQL

Cloud Deployment

  • Microservice architecture
  • Containerizing a REST API
  • Observability with OpenTelemetry
  • Running serverless on Azure

Private team training

Bring this course to your team

Tell us about your team and we will tailor this outline to your tools, stack, and schedule. Courses can also be combined into a longer program.

  1. Tell us what you needYour tools, stack, team size, and timeline.
  2. We send a proposalA course or program, an outline adjusted to your team, and possible dates.
  3. Your team trains liveOnline or on-site, with courseware for every student.

Prefer to talk? Call +1 434-509-6890 or email help@cloudcontraptions.com.

We reply within 1 business day.

Training partner?