2023-04-18 –, Kuppelsaal
An exchange of views on fastAPI in practice.
FastAPI is great, it helps many developers create REST APIs based on the OpenAPI standard and run them asynchronously. It has a thriving community and educational documentation.
FastAPI does a great job of getting people started with APIs quickly.
This talk will point out some obstacles and dark spots that I wish we had known about before. In this talk we want to highlight solutions.
An exchange of views on fastAPI in practice.
FastAPI is great, it helps many developers create REST APIs based on the OpenAPI standard and run them asynchronously. It has a thriving community and educational documentation.
FastAPI does a great job of getting people started with APIs quickly.
This talk will point out some obstacles and dark spots that I wish we had known about before. In this talk we want to highlight solutions.
This talk will include the following:
fastAPI is built on the shoulders of giants I: pydantic
FastAPI makes extensive use of pydantic. pydantic parses data, can validate (and transform) data, and has built-in interfaces to export OpenAPI definitions among many other features.
fastAPI is built on the shoulders of giants I: starlette
Routes and middleware are managed by starlette. In this section we will explore how to create custom middleware and what we learned along the way.
fastAPI has tutorials, but is this documentation?
The fastAPI page provides a good introduction. The more we worked with fastAPI, the harder it was to find accurate documentation. Looking at the source code, we really missed DocStrings! Introspection to the rescue - will probably include a rant about missing DocStrings!
DRY ("Don't repeat yourself") with pydantic
For our use case, we decided to use strict models to validate our data structures, as we work in a highly regulated industry where no mistakes are allowed to happen. Setting up the REST API was much easier than developing consistent models that generalise well. We follow the "single source of truth" paradigm, entering redundant definitions is an absolute no-go.
In this section we show how to create highly reusable pydantic model pools with inheritance for use in fastAPI. For testing, we also created models from metadata!
"The road not taken": pydantic Depends()!
API routes often consist of a request model and a response model. But what about cases where the models alone don't work and a model and e.g. query parameters need to be mixed?
Apart from flake8 complaining about having callables in the signature, this can be quite a difficult use case. Strategies for resolving model/parameter conflicts.
Bonus - if time:
Integrating fastAPI with Sphinx.
Demonstrate how to integrate OpenAPI with your Sphinx documentation.
The talk will show how fastAPI is built and how well introspection can help you understand what is going on under the hood and which library is actually doing the heavy lifting where.
5 Things about fastAPI I wish we had known beforehand - An opinionated talk about fastAPI in practice.
Alexander C.S. Hendorf is an independent AI and open-source strategy advisor working with companies in regulated industries. With 20+ years of hands-on experience across 50+ technologies — from the Python ecosystem to vector databases — he bridges the gap between boardroom decisions and technical execution. Alexander is a Python Software Foundation Fellow, serves on the board of the Python Software Verband and has delivered 100+ talks in 15+ countries.
He writes at hendorf.com