FastAPI for ML
From a predict() call buried in a notebook to a hardened HTTP service that a dashboard, a mobile app and a batch job can safely call in production.
Course Duration: 5h
What You'll Learn
- Expose a Python function as a typed HTTP route with generated documentation
- Validate request payloads with Pydantic and return meaningful 422 errors
- Load a model once at process start rather than at every request
- Serve single predictions and vectorized batches from the same service
- Distinguish 400, 422 and 500 responses and never leak a Python traceback
- Add async routes and background tasks for file-scoring jobs
- Protect the service with an API key or a JWT, and rotate keys safely
- Add structured logs, a health probe and a readiness probe
- Ship the service as a small, non-root Docker image with multiple workers
- Run a Locust scenario, read percentiles, and size workers and replicas
Prerequisites
- Python (course 02) and a trained model (course 04 or later)
- Basic Docker: images, containers, environment variables
Course Modules
- FastAPI: routes, types and automatic documentation
- Input validation with Pydantic
- Loading the model at startup
- Single and batch prediction
- Error handling and status codes
- Async requests and background tasks
- Token authentication
- Logging and health probes
- Containerization and deployment
- Load testing and sizing
The running example
Every module extends the same churn scoring API used by the Streamlit dashboard from course 38 and packaged with the MLOps workflow from course 20. Module 1 opens with a ten-line application. By module 10 the service validates inputs, loads a versioned model at startup, streams batches, returns structured errors, enforces an API key, emits structured logs, exposes a health probe, ships as a scanned container, and holds a measured load target with a documented number of workers and replicas.
Assessment and certificate
The course ends with a 40-question exam covering every module. On success, a certificate of completion is issued; its number is verifiable on the platform.
Free courses, by contrast, end with a 5-question quiz and a preview of the certificate, without certification.