Better Programming

Advice for programmers.

Follow publication

Why You Should Stop Using Flask and Start Using FastAPI

I swear you won’t regret it

Fahmi Nurfikri
Better Programming
Published in
4 min readOct 16, 2020

Photo by Pankaj Patel on Unsplash

When it comes to machine learning production, usually we’ll wrap a model into a rest API. Because making machine learning APIs doesn’t really require complex things — it only requires the predict() function — we usually only use a simple framework. And the framework we usually use is Flask.

Don’t get me wrong: Flask is good, but it’s in the past. One reason Flask is widely used is that in the past, not many people deployed models as real-time production APIs. For some people, Flask is good enough because it’s popular, minimal, and written in Python.

As time’s gone by, the production of machine learning, as a field, has matured. However, as this field has matured, features that were originally just nice to have become essential. And that’s a feature that Flask doesn’t have, so sometimes we have to use third-party dependencies, and sometimes the documentation isn’t too clear.

This is what made me look for other alternatives to create real-time production APIs. In the end, I found a web framework called FastAPI. FastAPI is a relatively new web framework for Python but is powerful and enjoyable to use. Here are some reasons why you should start using FastAPI.

Documentation

FastAPI has very extensive documentation and rich examples, which makes things easier. If you need to look for something having to do with FastAPI, you usually don’t need to look anywhere else.

In addition, FastAPI will automatically generate interactive API documentation from the program we’re running so we don’t need to write the API documentation that we created ourselves.

As we all know, writing API documentation is annoying, not only because there’s a lot of detail to go into but also because there’s nothing more frustrating than when end users are implementing but not matching up with the documentation. So the automatic generation of API documentation is very helpful.

Below is a display example of the API documentation (provided by Swagger UI):

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Fahmi Nurfikri
Fahmi Nurfikri

Written by Fahmi Nurfikri

Mostly writing about Programming and Artificial Intelligence | Follow me on https://github.com/fahmisalman and https://www.linkedin.com/in/fahmisalman

Responses (2)

Write a response