If you have read some of my previous Python articles, you know I’m a Flask fan. It is my go-to for building APIs in Python. However, recently I started to hear a lot about a new API framework for Python called FastAPI. After building some APIs with it, I can say it is amazing!

This project was created by Sebastian Ramírez, and at the time of writing, it has accumulated almost 20K stars. Big names like Microsoft, Uber, Netflix, and others have been building APIs with it.

But why is this new library so popular and how does it compare to Flask or Django?


Features

FastAPI is a rather minimalistic framework. However, that doesn’t make it less powerful. FastAPI is built using modern Python concepts and is based on Python 3.6 type declarations. Let’s see some of the features this library is packed with.

Automatic docs

A must-have for any API is documentation about the endpoints and types. A common approach to solve this problem is the use of OpenAPI and tools like Swagger UI or ReDoc to present the information. These come packed automatically with FastAPI, allowing you to focus more on your code than setting up tools.

Typed Python

This is a big one: FastAPI makes use of Python 3.6 type declarations (thanks to Pydantic). This means that it uses a Python feature that allows you to specify the type of a variable. And this framework makes extensive use out of it, providing you with great editor support. Autocompletion works amazingly well.

Here is some sample code using typed declarations:

#python #data-science #api #software-development #programming

Quickly Develop Highly Performant APIs With FastAPI and Python
1.20 GEEK