Course
Digicomp Code PYTAPI
Python Scalable APIs – with FastAPI and Flask («PYTAPI»)
Course facts
- Gaining an overview of Flask vs. FastAPI and comparing them
- Understanding the architecture of modern, scalable APIs
- Processing asynchronously and performance tuning
- Developing REST APIs with both frameworks in a practical way
- Validating, serialising and documenting with Pydantic and Swagger
- Focusing on testability and extensibility
- Understanding benchmarking and scaling scenarios
- Knowing best practices for production-ready API projects
This practical course demonstrates how to develop powerful, scalable APIs using Python. We compare the popular frameworks FastAPI and Flask, demonstrating their respective strengths and areas of application. Through hands-on exercises, you will learn to build and optimise your own RESTful APIs for performance and scalability, developing a sound understanding of modern API architectures in Python.
1 Overview and comparison: Flask vs. FastAPI
- History and objectives of both frameworks
- Synchronous vs. asynchronous programming model
- Differences in routing, middleware, dependency injection
- Community, extensibility and ecosystem
- When is which framework suitable?
2 Architecture of modern, scalable APIs
- Layered architecture: routers, services, repositories
- API design principles (REST, stateless, idempotent)
- OpenAPI / Swagger integration out-of-the-box
- Separation of business and infrastructure logic
- Caching, rate limiting, authentication
3 Asynchronous processing and performance tuning
- Introduction to async/await in Python
- WSGI vs. ASGI – differences and implications
- Performance benefits of async I/O (e.g. for database access, HTTP requests)
- Use of background tasks and queues
- Comparison of servers: Uvicorn, Gunicorn, Hypercorn
4 Practical development of REST APIs with both frameworks
- Project setup and structuring for Flask and FastAPI
- Route definition, path parameters, query parameters
- CRUD endpoints based on an example (e.g. «ToDo» app, blog, shop)
- Database connection with SQLAlchemy or Tortoise ORM
- Integration of external APIs / services
5 Validation, serialisation and documentation with Pydantic & Swagger
- Introduction to Pydantic: Typing, validation, defaults
- Creation of request and response models
- Automatic OpenAPI generation and Swagger UI
- Use of tags, description texts and examples
- Efficient validation of data
6 Focus on testability and extensibility
- Unit tests and integration tests for API endpoints
- Test clients in FastAPI and Flask
- Mocking external dependencies
- Structuring for extensibility: services, blueprints, routers
- Dependency injection and configuration management
7 Benchmarking and scaling scenarios
- API benchmarking with tools such as ab, wrk, locust, k6
- Comparison of the runtime performance of FastAPI vs. Flask
- Scaling with Gunicorn, Uvicorn Workers, Docker & Kubernetes
- Load balancing and horizontal scaling
- Health checks and readiness probes
8 Best practices for production-ready API projects
- Logging, monitoring, tracing (e.g. with Prometheus, OpenTelemetry)
- Dealing with errors & exceptions (global handlers, structured error outputs)
- Security aspects: CORS, Auth, HTTPS, rate limiting
- Continuous integration / deployment (CI/CD) with Docker & GitHub Actions
- Versioning of APIs (URI, header, media type)
This course creates a sound understanding of the two web frameworks through an optimal mix of short theory blocks, guided exercises, practical examples and hands-on scenarios.
This course is ideal for developers who want to develop clean, maintainable and high-performance interfaces with Python using the two powerful web frameworks FastAPI and Flask.
We recommend the course «Introduction to Programming with Python» as preparation: