Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

As others mention, Flask has more batteries included in terms of built-in templating, ORM, etc, so it positions more as a backend webserver.

FastAPI is more focused on making it easy to make APIs, especially with the built-in Swagger docs generation (I don't believe Flask has this out-of-the-box).

So if your greenfield project is more web-based (clients are web browsers), Flask may be more suited. If your greenfield project is service-based (command line applications, or front end), FastAPI may be more suited.

In both cases, it's as easy to substitute one for the other. Personally I'll be trying out FastAPI since the dev experience seems a lot nicer (integration with `pydantic`).



It's also worth mentioning that FastAPI/Starlette are async and a bit more annoying to debug.


flask also supports async now, that's one of the main new features of this release.


I believe Flask 2.0 optionally supports it whereas FastAPI is async only. I could be wrong though.

Edit: Thanks for the correction, my point is moot and irrelevant.


FastAPI happily supports both options in a gradual manner. Just start out sync and convert to async if you want on a per-route basis.


That's not exactly accurate. When working with sync views FastAPI dumps them into a threadpool. It basically converts them to async on the fly. To quote the docs-

> When you declare a path operation function with normal def instead of async def, it is run in an external threadpool that is then awaited, instead of being called directly (as it would block the server).


FastAPI allows you to define non-async views.


pip install flask-swagger flask-swagger-ui

Flask itself doesn't support swagger out of the box (much like security or login/auth) but the community has you covered.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: