AskReference
ComparisonIntroductory

What is the main difference between Flask and FastAPI in terms of asynchronous support?

The main difference is that Flask is synchronous and based on WSGI, whereas FastAPI uses ASGI and supports asynchronous request handling.

Flask is a synchronous framework built on the WSGI specification, meaning it handles requests in a traditional blocking manner. FastAPI, in contrast, is built on ASGI, which supports asynchronous web applications. The book notes that a separate project called Quart replicates Flask while adding ASGI support. Because FastAPI is ASGI-based, it can run faster than Flask in many cases, particularly for applications that benefit from async concurrency.

Key points

  • Flask is synchronous and based on WSGI.
  • FastAPI is ASGI-based and supports asynchronous handling.
  • Quart is a separate project that replicates Flask with ASGI support.
  • FastAPI's ASGI support can allow it to outperform Flask in many cases.
Source:FastAPI: Modern Python Web Development· Framework Comparisons· p. 101–110

Related questions

Cover of FastAPI: Modern Python Web Development

FastAPI: Modern Python Web Development

Bill Lubanovic;

First Edition · O'Reilly Media, Inc.

View this ebook