I understand that Flask has become popular because it is easy to learn, but my experience is that as your knowledge progresses it just keeps getting in your way. I particularly dislike some design choices which look like afterthought hacks, such as global variables for current request and using abort() functions instead of raising exceptions directly. EDIT: To avoid hollow naysaying, here are some alternatives to Fla…
I've never seen Falcon, thanks. Flask is still one of the most approachable frameworks I've used. It's great for getting something hacked out really quickly, but for asynchronous requests Tornado is where it's at. That being said, when I really want performance I usually reach for Golang.
Flask 1.0 Released
61–70 of 184 posts
Re: Flask 1.0 Released
#62Earlier quoted context omitted.
Flask _does_ scale really well with lines of codes. However the limitations of Python w.r.t. async log really start to show once you step beyond simple CRUD apps.
This was my experience. Just exited a startup that relied on Python heavily. Built a flask-restful based back end with SQL Alchemy.. Never had any issues with flask per say, but it made me happy I know languages with far better tooling and concurrency experience/performance :)
My use-case was I was doing a heavy part of an ETL pipeline out of MySQL and it was taking an unreasonable amount of time. PyPy was a roughly ~8x speedup, which ended up being faster than doing direct manipulation with MySQL via the cli (!!!).
Re: Flask 1.0 Released
#63Earlier quoted context omitted.
Flask _does_ scale really well with lines of codes. However the limitations of Python w.r.t. async log really start to show once you step beyond simple CRUD apps.
Just use sanic. It's a mostly drop in replacement for flask that is async first and runs on uvloop.
Re: Flask 1.0 Released
#64It was the biggest reason why I choose this job, as many python shops seem to run Django which I'm not a fan of.
Re: Flask 1.0 Released
#65Earlier quoted context omitted.
I agree. I particularly like Go's web ecosystem. A web server is just a function, and that function is often a composition of other functions (for example, a tree of router functions and then a handler for each route). By contrast, it seems like Flask goes to great lengths to obscure such a simple concept (decorators for routes, global variables for state and resource management, etc).
I wouldn't call it obscure, it's just an abstraction. But you can always use the underlying library ( http://werkzeug.pocoo.org/ ), which does send everything through a function. Or just implement WSGI directly.
It would be much cleaner to just define a handler type with the signature: `def handler(r: http.Request) -> http.Response`. Those handlers could be passed to routers (which themselves could be handlers), for example (not tested):
class Route(typing.NamedTuple):
path: typing.re.Pattern
method: str
handler: http.Handler
class Router:
def __init__(self, routes: typing.List[Route]) -> None:
self.routes = routes
def serve_http(self, r: http.Request) -> http.Response:
"""serve_http implements the http.Handler interface"""
for route in self.routes:
if route.path.matches(r.path):
return route.handler(r)
return http.NotFound("404 NOT FOUND")
Note that since handlers are just functions, they can also be methods with object-level state. They needn't depend on global state at all, for example, notice how the following routes don't depend on the connection pool (or the request state) to be global: class Server(typing.NamedTuple):
db: DBConnPool
def first_route(self, r: http.Request) -> http.Response:
"""first_route uses shared `db` resource."""
pass
def second_route(self, r: http.Request) -> http.Response:
"""second_route uses shared `db` resource too!"""
passRe: Flask 1.0 Released
#66Love Flask in theory. My biggest complaint was trying to do user management with it. Flask-Security was good, but the developer skipped town a few years ago. Did they come back? :D Basically you are left to your own devices, which sounds great, but user+auth is pretty fundamental to be left to a random absentee third-party in my opinion.
Yet no Flask application I've ever written needed user auth :)
Re: Flask 1.0 Released
#67Earlier quoted context omitted.
Flask _does_ scale really well with lines of codes. However the limitations of Python w.r.t. async log really start to show once you step beyond simple CRUD apps.
Just use sanic. It's a mostly drop in replacement for flask that is async first and runs on uvloop.
Re: Flask 1.0 Released
#68Flask has a stigma for not being that good when building larger apps, but honestly Flask scales really well for that type of use case (coming from a development / maintenance point of view). I have some pretty large Flask apps with dozens of top level dependencies and models spanning across many thousands of lines of code. Even if I don't touch the code base for a few months, it's easy to jump back into it. I'm also…
Re: Flask 1.0 Released
#69Love Flask in theory. My biggest complaint was trying to do user management with it. Flask-Security was good, but the developer skipped town a few years ago. Did they come back? :D Basically you are left to your own devices, which sounds great, but user+auth is pretty fundamental to be left to a random absentee third-party in my opinion.
Try farming out the auth to a middleware. That's what I do and it works really well.
Re: Flask 1.0 Released
#70Earlier quoted context omitted.
That sounds like a helleva large codebase, especially for Python. What did the application do? How large was the dev team?
I have worked on several Python code bases exceeding 500k lines. Not sure why you think that's uncommon.
I've managed to do python for 10 years only working on one codebase that size, and I'm not sure it counts - it was made by low skilled devs (we were encouraged not to do anything "clever", like use the language features) mostly cutting and pasting existing code.