4D Training & Consultancy

Software Development

Building Production APIs with Python and FastAPI

Python developers often ship an API that works in development and then meets real traffic, real clients, and real error cases. This course covers async request handling, Pydantic validation, dependency injection, authentication, versioned OpenAPI contracts, structured errors, automated testing, and containerized deployment.

4 daysIn-house, online, or customized deliveryCorporate teams and professional groupsLevel: Intermediate

Overview

Practical learning for workplace transfer.

The gap between a working FastAPI endpoint and a production API is filled with the things tutorials skip: what happens when a downstream call blocks the event loop, how a client learns that a field changed, where authentication tokens are verified, and what an error body must contain for an integration partner to debug without calling support. Participants build one service across the course, adding typed request and response models, injected dependencies and database sessions, token-based authorization, a published OpenAPI contract, a test suite that runs without a live database, and a container image ready for deployment.

Prerequisites

Working Python knowledge including functions, classes, and package management. Familiarity with HTTP and relational databases is helpful but not required.

Objectives

  • Build asynchronous FastAPI endpoints without blocking the event loop.
  • Model request and response payloads with Pydantic validation and typed schemas.
  • Manage database sessions, configuration, and clients through dependency injection.
  • Implement token-based authentication and per-route authorization rules.
  • Publish and version an OpenAPI contract that integration partners can build against.
  • Test, containerize, and deploy the service with health checks and structured logging.

Target audience

  • Python developers building or maintaining backend services
  • Backend engineers migrating from Flask or Django REST Framework
  • Data and machine learning engineers exposing models as services
  • Integration developers publishing APIs to partners and internal teams
  • Full-stack developers responsible for their own service layer
  • Technical leads setting API standards across Python teams

Program outline

A clear structure for the learning journey.

Program outline

Outline points are grouped in one designed block instead of being treated as separate module cards.

Module 1: FastAPI Fundamentals and Async Request Handling

Routing, path and query parameters, and the request lifecycle

Async and synchronous endpoints and what actually blocks the event loop

Background tasks, concurrency limits, and long-running operations

Project structure for a service that will grow beyond one file

Module 2: Data Validation and Schema Design with Pydantic

Request and response models, field constraints, and custom validators

Separating internal domain models from public API schemas

Serialization, aliases, and handling optional and nullable fields

Validation errors that tell the caller exactly what to correct

Module 3: Dependency Injection, Persistence, and Configuration

The dependency system: scopes, overrides, and shared resources

Database sessions, connection pooling, and transaction boundaries

Settings, secrets, and environment configuration without hard-coding

Injecting HTTP clients, caches, and third-party services for testability

Module 4: Authentication, Authorization, and API Protection

OAuth2 password and bearer flows, token issuance, and verification

Route-level and resource-level authorization rules

CORS, rate limiting, and request size and timeout controls

Credential handling, key rotation, and audit-relevant request logging

Module 5: Contracts, Errors, and API Versioning

Generated OpenAPI documentation and keeping it accurate as code changes

Consistent error envelopes, status codes, and problem details

Versioning strategies and deprecating an endpoint without breaking clients

Pagination, filtering, and idempotency for write operations

Module 6: Testing, Packaging, and Production Deployment

Testing endpoints with pytest, test clients, and dependency overrides

Fixtures and fakes that remove the need for a live database

Containerizing the service with Uvicorn and a production process manager

Health checks, structured logging, and metrics for a deployed service

Materials provided

  • Course workbook, annotated code samples, and reference notes
  • Hands-on lab environment and starter repositories
  • Exercises, checklists, and reusable code templates
  • 4D Certificate of Completion
  • Post-course technical guidance

Training Options

Programs can be delivered in-house, online, or in a blended format depending on your team's schedule, location, and learning objectives. When an external certificate or exam is included, certification rules and fees remain under the relevant awarding body's policies, while 4D provides the training and preparation support.

Why choose 4D

4D shapes this course around the integrations your service must actually support, whether internal consumers, partner systems, or model-serving endpoints. Participants finish with a running FastAPI service, a published OpenAPI contract reviewed against your integration requirements, and a test and deployment setup their team can extend immediately.

Speak to 4D

Plan the right training or consultancy path for your team.

Share a few details and 4D will help route your inquiry toward corporate training, consultancy, assessment, Phoenix-enabled support, or a tailored program.