Skip to content

SchernHe/api-framework-comparison

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API Framework Comparison

This repository gives a small overview and comparison for both Flask and FastAPI.

Table of Content:

Install

poetry install

Run Python APIs

FastAPI

After the installation, you can start the FastAPI backend via:

poe start-fastapi

You can open the OpenAPI definition in http://127.0.0.1:8000/docs.

Flask

After the installation, you can start the Flask backend via:

poe start-flask

Comparison Table

Flask FastAPI
2010   2019
Micro framework Full-Stack framwork
Async support from > v2.0 Async first
License: BSD-3 Clause License: MIT
No built-in data validation Built-in data validation with pydantic
Out-of-the-box OpenAPI documentation

Discussions

Performance

Apparently, there are a few discussions online regarding the speed of both frameworks. Initially, FastAPI was supposed to be the faster framework due to the async-first implementation. However, with version 2.0, Flask also added async support:

FastAPI - When to use async

Similarly, there are also some open discussions whether one should always define routes in FastAPI with async or not:

For normal path operation functions (without async), the function is run in an external threadpool that is then awaited, instead of being called directly (See: documentation).

The only official answer (discussion 10771) states:

FastAPI is an async framework, and async should the be the default choice.

and that the "threadpool def endpoints" are merely an escape hatch.

About

Demo repository to compare Python API frameworks

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published