Live data from Hacker News

Flask 1.0 Released

palletsprojects.com

61–70 of 184 posts

Re: Flask 1.0 Released

#61
post #21

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.

Check out Sanic if you want an async python framework with a similar API to flask

Re: Flask 1.0 Released

#62
post #55

Earlier 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 :)

Did you ever attempt to use PyPy? Flask works with it, and in my experience the handful of times I've needed Python to be more performant, PyPy got me there easily.

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

#63

Earlier 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.

Quart is another option. Even more of a "drop-in replacement" than sanic.

Re: Flask 1.0 Released

#64
We (a big newspaper - 5k-10k visitors at any time) run on Flask. Quite a big application.

It 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

#65
post #14

Earlier 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's not a very good abstraction, because (as previously mentioned) it depends on global variables to manage shared resources (e.g., connection pools) and even request state. Hence "obscure".

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!"""
            pass

Re: Flask 1.0 Released

#66

Love 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 :)

Indeed, its a risky choice for that.

Re: Flask 1.0 Released

#67

Earlier 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.

The unfortunate bit is you lose out on so much of the ecosystem going hard on asyncio right now though (like sqlalchemy orm).

Re: Flask 1.0 Released

#68
post #28

Flask 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…

I think that's more because Flask is a micro web framework whereas Rails is a macro web framework. Sinatra, Express, and Compojure are micro frameworks in the same vein as Flask, and they encourage simplicity of mental model over batteries-included comprehensiveness of features that you find in Rails, Sails, and Django. In general I prefer some kind of a middle ground but I don't think there's middle-ground frameworks actually out there, I think you have to kind of build on top of Flask/Sinatra/Express by throwing some-batteries-included libraries on top of them to get there. But yeah I also find it easier to reason about than having a whole lot of convention-over-configuration rules memorized.

Re: Flask 1.0 Released

#69

Love 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.

Does it interface with sqlalchemy, onboarding, email, etc?

Re: Flask 1.0 Released

#70
post #33

Earlier 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.

There are a lot of different types of software being made in python.

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.

Post reply on HN