FastAPI vs Flask

M Bilal Alpaslan
2 min readJan 15, 2023

--

FastAPI and Flask. Both python micro framework and look same in the first review. But in a long use uncover many differences. In this article we will discuss these differences.

FastAPI vs Flask

Performance

FastAPI depends Starlette and Uvicorn. High performans ASGI framework. Flask is a WSGI framework and when compared this fraework fastAPI performans better than Flask.

Python Async support

FastAPI is an fresh framework comes with built-in async await support but Flask is old framework in the API development ecosystem and it can’t support. It can handle one request at the time.

Routing

FastAPI and Flask use the same mothed for routing. Decorator based routing.

Middeware Support

FastAPI support ASGI middewares and Flask support WSGI middewares.

Data validation

FastAPI works with Pydantic models for data validation by default(not only validation). Flask does not have built-in data validation. But you can integrate Pydantic or someting else manually.

Type Hints

FastAPI has built-in type hints validation support and it’s belongs with python otocomplete support. In flask you can write with type hints but Flask doesnt have otomatic validation.

Html Rendering and Templates

Flask has a built in Jinja2 supports. But Fastapi does not have this feature by default and you must integrate manually.

Other FastAPI Features

FastAPI collect routes detail for creating OpenAPI spec for feed Swagger docs by default.

Other Flask Features

Flask don’t need Uvicorn for development. Flask have a built-in development server.

Conclusion

Actually I don’t write a conclusion about this comprension because I am wondering yours opinion.

--

--

M Bilal Alpaslan
M Bilal Alpaslan

No responses yet