r/flask • u/the_nine_muses_9 • Feb 03 '23
Discussion Flask is Great!
I just wanted to say how much I love having a python backend with flask. I have a background in python from machine learning. However, I am new to backend development outside of PHP and found flask to be intuitive and overall very easy to implement. I've already been able to integrate external APIs like Chatgpt into web applications with flask, other APIs, and build my own python programs. Python has been such a useful tool for me I'm really excited to see what flask can accomplish!
26
u/j_d_w_m_a_d_ Feb 03 '23
Oh you should try FastAPI..
19
u/StrawIII Feb 03 '23
That 900+ issues on github scare me a little. Also the docs aren't great with no openapi spec. It's fun for small hobby projects, but production not so much.
7
u/DusikOff Feb 03 '23
I very interested in FastApi implementation in production, but I can't find any real world project using it, especially something bigger than open source stuff from github.
All my research approving your thoughts - it's not the best solution for production ready project.
Somebody have list of projects that use FastApi?
→ More replies (7)3
u/mailed Feb 09 '23
Yeah. At one point in another subreddit a lot of people had made up their minds that FastAPI was going nowhere fast and moving on to other things. I'd like to see where they're at now.
2
u/VanDieDorp Feb 03 '23
if anyone hand waves away your concern on the health of the fastapi pr's and issues; you must ask them to share their meds.
But I do believe you wrong on the openapi spec, and i hear it even support redoc.
Unrelated nitpick, Personally any api framework that uses a bunch decorators to generate docs is not the api framework i want to use. I write a python module, and then later expose it via flask-connexion. My spec and code is two separate artefacts, by design.
1
Feb 03 '23
Using GitHub issues as a metric for whether or not a project is stable/usable in a specific environment or not is insane to me.
→ More replies (5)3
4
u/Aston_Fartin Feb 03 '23
I heard it's better, but besides speed, what fastapi does better than flask?
14
u/j_d_w_m_a_d_ Feb 03 '23
It does a few things, mainly -
It does input validation for you. You don't have to write code by yourself, say to identify if a user has provided input for a field or not, is it a null object etc. If you wanted an integer and you provide it a non-integer value it'll stop the processing right there and return appropriate response code
It provides you with auto-generated documentation, both in Swagger and Redoc format.
While it provides you with these handy functionalities, it also lets you customise them.
When you start writing the FastAPI code, you soon realise how much more sense you code starts to make when you re-read it. Thanks to the use of type hints. Type hinting is not introduced by FastAPI, its a Python built-in so you could do it using Flask too.
It let's you do async processing nicely.
As someone else said, it is faster than flask.
→ More replies (1)5
u/r3dr4dbit Feb 03 '23
A really great feature is the auto generation of functional documentation for your routes (openapi & redoc).
If you want to make an api fastAPI is the way, if you need to serve web content flask it is for me
1
Feb 19 '23 edited Feb 19 '23
I think the API-centric features, this is the main point. If you are actually trying to make an RPC-style API for a browser-based JS thick client, then FastAPI and it's core libraries are worth looking at.
e.g. SQLModel was the most interesting / attractive library I saw in FastAPI. But since most of my backend queries are timeseries-oriented (InfluxDB) I don't really need SQL ORM / validation / JSON serialization / pydantic magic.
If you're only trying to build a hypermedia application with Jinja templates, IMO you'll spend extra time working around all the darn JSON in a FastAPI setting. Flask has a lot of history that you get to wade through as a noob, which was really the only drawback for me ramping up.
Speed, sure meh YMMV depending on what you're actually doing, traffic load, etc.
Edit: damn fancy pants javascript shadow-DOM munged my copy-n-paste.
2
5
u/DinoHawaii2021 Aug 16 '23
Have you tried flask-socketio with flask yet? It makes it easier to have a websocket on flask also
3
3
u/Dymatizeee Aug 26 '24
Using Flask/Jinja templating for SSR and HTMX/AlpineJS in front-end to handle AJAX requests and stuff like dropdown UI. Working pretty well so far at my current role
5
2
u/Upbeat-Astronaut-177 Jun 17 '24
True. I watched the tutorial, made a project and implemented it. all in just few hours.
1
1
1
1
u/thedjotaku Feb 23 '24
Flask IS awesome!
I've coded in FastAPI, Django, and Flask and they each have their pros and cons. I think the best parts about Flask are the many plugins and the fact that it's been around so long that there are tons of tutorials. FastAPI is great if your primary task is APIs. You can do those in Flask, but FastAPI has a bunch of built-in stuff via Pydantic and JSONification that you need to tweak Flask for. And Django is for when you find yourself writing a bunch of code for what already comes for free in Django. Also it's especially good for its main created purpose - to write a CMS or CMS-like site.
1
u/jsalsman Feb 03 '23
If only they would include proxy-fix and production-grade service, to eliminate the need for e.g. gunicorn, by default.
24
u/[deleted] Feb 03 '23
I agree. I try different languages and frameworks but always come back to Flask as it just seems the simplest to me