r/FastAPI • • Jul 29 '21

Question What does Flask have that FastAPI doesn't currently have?

I would like to help FastAPI/Starlette overtake flask to become the de facto framework for microservices and REST APIs. (I think Django projects generally target a different use case so I'm less concerned with trying to gain feature parity with Django)

I'm currently creating a comparison of similar 3rd party libs from each framework by cross-referencing:

I'm wondering if any of you with flask experience ever have feelings of:

I wish FastAPI had an equivalent of flask feature/plugin 'X'

Depending on the scope of the feature I'd like to try to implement or improve the biggest gaps between FastAPI and flask. Either by contributing to an active repo or creating my own.

For context, I've been working with FastAPI/Starlette/pydantic and asyncio on/off for around 2 years.

15 Upvotes

12 comments sorted by

4

u/Gnlfbz Jul 30 '21

One of the things I would like to be easier in FastAPI is changing the logging around. On my recent project I wanted to get all of my logs into a JSON format and the work I had to do to make that work was kinda janky. Whereas when I have done it with flask in the past it has been pretty straightforward.

1

u/wrtbwtrfasdf Jul 31 '21

I just found this aiologger lib that has a JsonLogger and it reminded me of your post here. Hopefully since it's async and logs Json it helps you.

https://async-worker.github.io/aiologger/loggers_jsonlogger.html

3

u/Gnlfbz Jul 31 '21

That is nice, but one of the big things that I did was overload all the original logs so that 100% of the logs (even those that I dont create myself) are json. I originally went through the suggestions in https://github.com/tiangolo/uvicorn-gunicorn-fastapi-docker/issues/19 and https://github.com/tiangolo/fastapi/issues/898 to craft my solution. However I see the following now that I want to checkout later https://awesomeopensource.com/project/bobbui/json-logging-python

7

u/SCUSKU Jul 29 '21

Because Flask is older, it does have more tutorials and weird edge cases answered on Stack Overflow compared to FastAPI. Also, there are a lot more Flask "plugins" that can help your project, that I don't think FastAPI has as many of yet. For example, Flask-Compress (https://pypi.org/project/Flask-Compress/).

16

u/ColdPorridge Jul 30 '21

The old tutorials and flask plug-ins can be as much of a curse though. I’ve been building a flask project for the last few months and I can’t overstate how annoying how much abandonware and out-of-date tutorials there are. As someone who has not been using it for years, it really is quite hard to find consistent best practices for Flask.

3

u/JustaDevOnTheMove Jul 30 '21

Agreed, finding the basics just to get started is easy but anything remotely real-life and production-worthy is much harder not to mention best-practices

0

u/[deleted] Jul 30 '21

[deleted]

3

u/PeterJHoburg Jul 30 '21

Async SQLAlchemy is pretty easy to do, assuming the DB dialect and driver you are using support async.

https://docs.sqlalchemy.org/en/14/orm/extensions/asyncio.html

And as far as I know Django ORM still isn't Async. Other parts of Django are finally async, but the ORM isn't.

0

u/[deleted] Jul 30 '21

[deleted]

2

u/wrtbwtrfasdf Jul 30 '21

I encountered the same issue with databases so I gave up on it(perhaps prematurely).

Unfortunately, SQLAlchemy is in a really weird spot right now with support split between 1.3,1.4, and 2.0. I think you more or less have to just settle for 1.3 if you want an async integration atm. I'd look into gino it's actively-developed and has FastAPI integrations. They are currently on sa v1.3 but plan to match their future releases with sa(ie v1.4 gino w/ v1.4sa, v2.0gino w/ v2.0sa ).

GINO - GINO Is Not ORM - is a lightweight asynchronous ORM built on top of SQLAlchemy core for Python asyncio

1

u/wrtbwtrfasdf Jul 30 '21

I thought I saw that we won the battle on the Typing PEP that would've broken pydantic?

0

u/[deleted] Jul 30 '21

[deleted]

1

u/wrtbwtrfasdf Jul 30 '21

Ahh I see you are correct. But at least it sounds like they are hopefully rewriting that PEP into something that will work for everyone.

https://www.reddit.com/r/Python/comments/muyz5h/pep_563_getting_rolled_back_from_python_310/gv93gyu/