FastAPI: Introducing the Best Python API Framework

Cakra Amiyantoro
DSF Web Services Engineering
3 min readJul 21, 2020

What is FastAPI?

FastAPI is one of the Python frameworks to build API. This framework is licensed by Massachusetts Institute of Technology (MIT). It has a quote:

FastAPI framework, high performance, easy to learn, fast to code, ready for production.

Why FastAPI?

FastAPI has many advantages. I will summarize only five of them:

1. FastAPI uses Python 3.6.x+ programming language. It is faster, the most popular, having many libraries, and is easy to learn.

2. Easy for Installation. We just need some tools like Python 3.6.x+ and Uvicorn.

3. FastAPI has modern features like automatic interactive documentation, Swagger download (structured API Json file to be used in other applications e.g. WSO2 API Manager).

4. The official FastAPI website has structured documentations and many developers.

5. It has good performance based on https://www.techempower.com/ (one of web framework benchmarks) until May 2020.

This is data on the popular programming languages based on PYPL Popularity of Programming Language Index:

Worldwide, July 2020 compared to a year ago

FastAPI Installation

· Download Python 3.6.x or higher and install it on your computer.

Official Python web site Accessed 20 July 2020

· Make sure your Python is installed. We can test it by typing “python” and “pip” commands in our terminal for Linux or command prompt for Windows.

Python is installed in computer
Pip command is running well

· Now we must install “FastAPI” and “Uvicorn” by typing in our terminal for Linux or command prompt for Windows.

pip install FastAPI uvicorn

· After the installation of FastAPI and Uvicorn is finished, we are ready to create the first application of API service. Here is the example:

First app FastAPI

· We can run the code by typing this on the terminal or command prompt:

uvicorn main:app - reload

· When the Uvicorn server is running well, the result will be like this:

Uvicorn is running well

· We can test the API using automatic documentation of FastAPI on this link:

The capture of FastAPI automatic documentation

· To test the service in FastAPI documentation, we should click the service and click “Try it out

Collpasing menu api of FastAPI

· Click the “Execute” button

Execute API of FastAPI

· Now your first FastAPI application is ready.

To explore all the FastAPI features, please visit the official website here.

Thank you and good luck…

References

https://FastAPI.tiangolo.com/ (Accessed 20/07/2020)

https://www.techempower.com/ (Accessed 20/07/2020)

https://pypl.github.io/PYPL.html (Accessed 20/07/2020)

--

--