Member-only story

3 Reasons to Switch to FastAPI

Flask vs. FastAPI

Kristaps Grinbergs
Better Programming
5 min readDec 2, 2020
Photo by Shahadat Rahman on Unsplash.

We’re living in a post-Python 2 world, as most companies have adapted to Python 3. The language is getting more mature. Recently, Python has been adopting cool things from other languages. A couple of examples are type hints and the async/await syntax.

Because of these changes to the Python language, it’s time we discuss the new beast in town: FastAPI. Let’s go over three advantages of choosing FastAPI over Flask based on my experience of using both for months.

After reading this article, you’ll understand when you should make the switch.

Async

The async/await syntax is something that was recently introduced in Python. Most programmers think this will speed everything up. That’s not quite true, as synchronous code is the way to go in most scenarios. Async/await is a way to write asynchronous code in a very convenient way.

In terms of API programming, this is very interesting. We see a rising need for asynchronous tasks like queuing, WebSockets, etc. Unlike Flask, FastAPI is implemented on ASGI and allows you to create both asynchronous and synchronous applications natively.

Imagine you’re writing an endpoint that retrieves pictures of animals. Every request can take some time. In the background, you might…

Kristaps Grinbergs
Kristaps Grinbergs

Written by Kristaps Grinbergs

Blockchain, mobile and fullstack developer. Startup founder. Conference speaker. Mentor. Passionate about building products, sustainability and Web 3.0.

No responses yet

What are your thoughts?