Lab 15: Capstone — Production Platform

Time: 90 minutes | Level: Architect | Docker: docker run -it --rm python:3.11-slim bash

Overview

This capstone integrates all 14 previous labs into a production-grade Python platform:

  • FastAPI app with Pydantic v2 models + custom validators

  • Custom import hook for config loading

  • Descriptor-based typed settings

  • asyncio with contextvars for request tracing

  • tracemalloc profiling endpoint (/debug/memory)

  • pluggy plugin system for request middleware

  • Prometheus metrics (Counter + Histogram)

  • Fernet encryption for sensitive fields

  • pytest with 8+ test cases

Install Dependencies

pip install fastapi uvicorn pydantic pluggy cryptography prometheus-client opentelemetry-sdk anyio

Step 1: Platform Configuration with Descriptors and Import Hooks

Step 2: Pydantic v2 Models with Custom Validators

Step 3: asyncio Request Tracing with contextvars

Step 4: Memory Profiling Endpoint

Step 5: pluggy Plugin System for Middleware

Step 6: Fernet Encryption for Sensitive Fields

Step 7: pytest Test Suite

Step 8: Capstone Integration — Run the Full Platform

📸 Verified Output (tracemalloc):

FastAPI Application

Summary

Layer
Technology
Lab Reference

Configuration

Descriptor + import hook

Lab 02 + Lab 03

Models

Pydantic v2 + validators

Lab 10

Request tracing

asyncio + ContextVar

Lab 06

Memory profiling

tracemalloc endpoint

Lab 04

Middleware

pluggy plugin system

Lab 13

Metrics

prometheus_client

Lab 12

Encryption

Fernet + EncryptedField

Lab 14

Testing

pytest + 8 tests

All labs

GIL-free workers

multiprocessing.Pool

Lab 08

Caching

functools.lru_cache + TTL

Lab 09

Checklist

Last updated