Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
New Werkzeug and Flask Releases (pocoo.org)
251 points by ch0wn on June 13, 2013 | hide | past | favorite | 57 comments


Flask is about the most beautiful Python code you can write. Check out any other Python framework and they may have a decent api, but on the inside it is messy and confusing. Reading Flask source code on the other hand is a joy. There's no crazy stuff and few convoluted pieces + lots of comments so it is really easy to hack something if you must. Any Python coder who wants to improve their game definitely should study Flask because it is such a great piece of software engineering.


Check out any other Python framework and they may have a decent api, but on the inside it is messy and confusing.

This is a really disingenuous generalization. If it's not Flask, it's messy and confusing? Telling every framework developer who's not the author of this one library that their code is crap not only isn't a great way to be taken seriously, it's wrong and just kind of mean.


The natural state of any large codebase maintained by multiple persons over multiple years is to be messy and confusing. Therefore it isn't a slight to anyone to state that the Flask devs have been able to keep their source code much cleaner than the average.


> There's no crazy stuff and few convoluted pieces

I dunno, I've recently started getting into it and "convoluted" is one word that has occurred to me more than once. Handlers vs signals, application and request context, context locals, local proxies, etc.. Probably there's a good reason for all these and the docs make a decent attempt to lay them out but overall my unscientific first impression is that it's not exactly a pinnacle of simplicity.


> application and request context, context locals, local proxies

Those are just different names for the same thing. Maybe the docs are a bit too in-your-face with the contexts but I rather expose people to it early to avoid issues down the line.

Django for instance does not have equivalents for application and request contexts and the end result is that people often write thread unsafe code and you can only have one application per Python interpreter. Flask does not have those restrictions. You can have as many Flask applications living side by side. And that is possible because of the contexts.


There is a difference. Having a request or application context that encapsulates state is one thing, an architectural decision that simplifies multi-tenancy and makes many uses of Flask more performant. These are "simple", in that they are an obvious and easily-explained solution to a technical problem that exists by necessity.

Global proxies to local state are another beast entirely. They are "easy" in that they remove the need to pass application and request objects through every called function, but they are not "simple" -- they rely on intimate details and peculiarities of Python's module and import system, and its capacity for thread-local state, not to mention Python's robust context unwinding features in the case of exceptions. Overuse of context-proxies leads to the same software engineering challenges as overuse of globals, in that it becomes difficult to reason about the calling semantics of functions which rely on context state being present, or mutate context state through proxies. For example, in order to test a view function, you will at a minimum need to set up an application context, but also need to set up any custom context your app relies on. It's not always obvious how to do this, leading to documentation [1] that I notice has already been confusing people on the mailing list.

So I wouldn't conflate the two mechanisms. Application- and request-local context is a pre-requisite for multi-tenant applications and a conceptual simplification. Module-level proxies are a cute trick that makes programmers' lives easier, but undoubtedly creates more convoluted semantics and internal operation.

[1]: http://flask.pocoo.org/docs/testing/#faking-resources-and-co...


I learned that you need context locals in web applications or beginners will write themselves into a corner where they have an architectural problem on their hand they can't fix later on.

Yes, it's not the best solution, but passing things around isn't either.


Not only is the code great, but so is the documentation, the release notes, and the community.


For what it's worth, the internals of Bottle are very clean (and extremely simple - the entire library/framework is just one file).


I know I'm biased on that, but if the internals of Bottle are clean it's doing something wrong :) WSGI/HTTP are incredible complex and in fact, too complex to fit into a single Python file.

There is a good reason for why Werkzeug (which Flask is based on) is 15000 lines of code.


It's in a single file which happens to be a little under 3500 lines long ...


Right, he's implying that the implementation is not as complete, or is incorrect because the problem space is more complex than that.


He is implying with not any evidence, aka FUD.


He is implying with the evidence that werkzeug which he wrote is much bigger than bottle owing to complexities of wsgi/http, and bottle's smaller size means either the implementation is incomplete or the implementation is too clever or both.


Still no evidence in your comment.

Repeating his "I had to make X big to support all of wsgi/http so anyone who made a similar framework but much smaller has made it incomplete or too succint and clever in a bad way" is not evidence.

You say:

>bottle's smaller size means either the implementation is incomplete or the implementation is too clever or both.

That's a statement of fact (actually a dichotomy of facts). What's the evidence to support these are the only two possible options?

The mere fact that Armin had to make Werkzeug bigger "owing to complexities of wsgi/http" is not proof.

To take it as proof is to assume his coding (and understanding of wsgi/http) as the golden standard by which the Bottle developer should be measured.

Who said this is the case? For one, it took him a year after Bottle to support Python 3, so he might not be that focused, anyway.

My problem is that, the way he and you say it, "incomplete" implies broken or lacking, whereas "too clever" implies fancy tricky code that's too succinct for it's own good.

How about the third option that he needlessly convoluted Werkzeug to work around wsgi/http edge cases that no one really faces, whereas Bottle has been pragmatic about it?

Or the fourth option, that Werkzeug is needlessly verbose, whereas Bottle is not "too clever" but just as clever as needed?


It would have taken less effort just to try out both frameworks, and then you wouldn't need anyone else's "evidence".


>It would have taken less effort just to try out both frameworks, and then you wouldn't need anyone else's "evidence"

I've tried both frameworks, and looked at the code for both, and I'm of the opposite opinion.

Yours is not a very suggestion. It presupposes what is asked to provide evidence for. That's called a circular argument.


I doubt he or she was aware it was 3500 lines long. While not the same as 15000, it isn't all that far off.


I am pretty certain that he, the_mitsuhiko (aka. Armin Ronacher), being the main developer behind Werkzeug and Flask knows exactly how long bottle.py is.


Yeah, I did't know who he was and I took it as a drive-by comment. I somehow missed the "I know I'm biased ..." bit unless he edited the post after I replied.


I've also found Tornado to be quite readable. But my norm is corporate closed source code which is pretty unreadable.


I agree here, I think Tornado is really quite readable. I was pleasantly surprised the first time that I looked at the source.


The Flask docs have a small write-up on the things to look out for before jumping ship to Python 3. http://flask.pocoo.org/docs/python3/


Congrats & well done guys :) Flask was the last major block preventing me from seriously moving over to Python3 so I guess that means it's time to begin porting! (there goes my weekend...)


Python 3 support! Now I can make the switch. Congratulations to Armin and all contributors, and a big thank you!


Terrific news! Many thanks to all who made it possible.

https://python3wos.appspot.com/ needs an update. :)


That will update once the author of flask updates its pypi entry.


So we're a PHP shop thinking about moving to Python. With this release, can we immediately start using version 3?

The Flask page still recommends holding back... (http://flask.pocoo.org/docs/python3/)


Like irahul has said, the issue is the Flask extension ecosystem and documentation lag rather than Flask itself. Which basically means YMMV depending on what you need to get done :)

If you are writing most of your own code and not using Flask extensions then you could well be fine (unless, like the linked post says, you discover a few months down the line you _do_ need a couple of extensions and they haven't been ported yet!).

Also worth pointing out that lots of other great python libraries now fully support python3 so you can get a lot done with just Flask on its own and those e.g. requests, redis-py, psycopg2, pytz.


> With this release, can we immediately start using version 3?

You should stick with 2.7 As mentioned in your linked blog post, porting Flask to Python 3 wasn't the issue. The issue is the other libraries which you will use to build your web application which aren't on Python 3 yet. You can try to build a unified code base(runs on both 2.7 and 3) http://lucumr.pocoo.org/2013/5/21/porting-to-python-3-redux/


I picked up flask for a one off helpdesk request frontend for someone a few months ago.

Compared to asp.net, its an absolute joy to work with. It makes me not want to grind my face off with a blunt spoon :)

Glad to see some awesome progress with it.


I read somewhere that Flask was born as an Aprils first joke.

So I ask. How safe is it to use in a real project? Is it a serious project today? Would you recommend Flask to someone who has never done any server side programming?


Yes, it's pretty reliable.

We (mailgun.com) use it in production, our deployment handles thousands of requests/sec, we have not seen any flask-related issues so far in 2+ years.

You can use pool of flask + twisted powered services behind nginxes:

Nginx ---upstream pool--> twisted.wsgi + thread pool + flask app

Something like that:

https://gist.github.com/klizhentas/5775158


Twilio uses it to run their API. So, that must be very reliable.

"Flask-RESTful was initially developed as an internal project at Twilio, built to power their public and internal APIs" http://flask-restful.readthedocs.org/en/latest/


We use a bunch of tools up and down our stack, but the nginx+uwsgi+Flask part of our stack has been very reliable.

Every request to new-ish parts of the Twilio API touches Flask, and it's performed like a champ.


While I'm not disagreeing on the quality of Flask, "x uses y, so y must be stable" is the same kind of argument as "Facebook runs on PHP, so PHP must be blazing fast." Yeah, there are large web companies using all sorts of tech, but what else they're using alongside it and how they've adapted it to their needs make this sort of commentary questionable at best.

It's definitely nice to see other responses here that are from people who are, first hand, using Flask in high-traffic live deployments. I'd just be careful about drawing conclusions based on who has it somewhere in their stack without any context.


>While I'm not disagreeing on the quality of Flask, "x uses y, so y must be stable" is the same kind of argument as "Facebook runs on PHP, so PHP must be blazing fast."

No, the argument is the same: "Facebook runs on PHP, so PHP must be stable".

Which makes sense. A base technology that holds up with half a billion users, I would call production ready.

As for fast, if you look at the most comprehensive benchmarks, PHP is more or less on par with Ruby/Python for raw speed of simple page serving, but when multiple DB connections are used in a page (which is the most common case for dynamic pages), it leaps far ahead, and reaches Servlet and Go levels of reqs/sec.


Fair enough in general, but I don't think my conclusion of "Twilio's API runs on Flask => Flask is very reliable" is too far-fetched in the context of Twilio, whose whole business is their API.

To be fair to your skepticism, I have probably followed Twilio more than you've had. I seem to remember that they switched to Flask, so I don't think it was technical debt that they had to work around later on. (like it might have been the case with Facebook and PHP)

Let's say that "Twilio uses Flask for their API" answers the question "can it be used in production?" (or "is it a serious project today?"). "Should you use it in production?" is where context matters more.


It's definitely production ready. We are using it everywhere in Close.io (http://close.io/)

If you're building a complex web app with it, just be sure to checkout all the Flask extensions so you don't have to reinvent the wheel too much.


Disqus were using it: https://ep2013.europython.eu/conference/talks/making-disqus-...

Though I think they may have recently replaced this bit of their architecture with Go?

FWIW, I've chosen Flask to power my startup and have no regrets at all. It's a joy to work with and rock solid :)


Regardless of Flask's humble beginnings, it is indeed a serious project, very stable, and quite awesome. And yes, I would recommend it for your use, assuming you want to learn Python as a whole. Flask is easy enough that you can start building an app right away, but at the same time, it leaves out all the extra 'magic' that ship with things like Django, so you'll be learning a lot more Python as you add onto your app. It's a great mix of simplicity and power, and is great for learning. Go for it.


I'm curious about what you think is "magic" in Django? It does have a lot more included than Flask/Werkzeug/Jinja2 but it did start in the era before Pip/VirtualEnv existed so a lot more had to be included.

After numerous purges (the magic-removal-branch being the biggest) and deprecations over the years since 1.0, Django is IMO pretty magic-free. If you have suggestions of what isn't Pythonic enough, I think the core team would appreciate a ticket on Trac:

  https://code.djangoproject.com/newticket


I think it's the different between a normal python application and a web app: url dispatcher/route, request handler, template, extension...I started with Django, but Flask clears thing better for me.


Please check out PyPI result page https://pypi.python.org/pypi?%3Aaction=search&term=flask&sub... it shows more than 400 related modules. Think it looks pretty serious.


We use flask at fusic.com and find it very reliable and easy to work with. Our peaks have over 1m rpm, and it has never fails us. We did a huge project migrating from Django, and now we don't have to jump through hoops so much.

I think flask has a front page that discourages newcomers, as it does not look as serious as Django, and gives the feeling that is it not mature enough, or documented. I tried convincing a new startup to use it and failed for those reasons.


I clicked this expecting a new release from Farbrausch : /


Unlikely, right? Also their stuff uses double-k, so it's werkkzeug IIRC..


Flask is a very solid python microframework and a joy to work with. So nice it is on Python 3 (3.3+) now. boto is the only thing needed for full on Python 3 here.


Here I was thinking this was about "werkkzeug" by Farbrausch


The popular demo!


pretty sure werkkzeug was the tool, not the demo


Yeah, just reminiscing.




The "Download page" link in http://werkzeug.pocoo.org/docs/installation/ needs to be fixed then!

(From the tarball release Download the most recent tarball from the download page.)


This is awesome. Been waiting to use it!


Time to update some extensions!




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

Search: