So, you want to wrap your machine learning model into an API. Flask used to be the best tool for that, but lately, FastAPI has become my favorite.
Here are my five main reasons why!
Here are my five main reasons why!


You define the request body model in Pydantic, write the endpoint function to process it, and finally register the route to the app.
That's it.
Icing on the cake: FastAPI automatically generates the OpenAPI specification and a Swagger UI, which you can use to try out your app.

You only have to append `async` before the function definition, and you can use async functions inside the endpoint function.

This is my favorite. You can inject complex dependencies into endpoints easily, which not only makes testing a breeze but can manage difficult tasks like authentication - in one line.
In the example below, I inject a "database" with minimal effort.

Working with databases can be a real pain in other Python frameworks. If you ever tried to make Django work with MongoDB, you know what I am talking about.
With FastAPI, it is simple and pleasant, like a cool summer breeze.

We all know GraphQL is awesome. You can add it to your app with Graphene + FastAPI easily.


FastAPI's documentation is on par with Django and Flask. As someone coming from the machine learning side, it also taught me a bunch of new things about web development.
Did I convince you? :) Have you tried FastAPI yet? What are your experiences?