7 ms·
Why so many Python web frameworks?
- espeed 15y agoBuilding a non-WSGI Python framework would be useful because WSGI does not support websockets (http://librelist.com/browser//flask/2011/12/30/websockets/#b8215c55f7d5121fed8b1db3d51b9ce4 http://librelist.com/browser//flask/2011/12/30/websockets/#b...). A ZeroMQ-based framework might be interesting -- Brubeck (http://brubeck.io/ http://brubeck.io/) is an example of this. Nginx (https://github.com/FRiCKLE/ngx_zeromq https://github.com/FRiCKLE/ngx_zeromq) is starting to get support for ZeroMQ, and Mongrel2 (http://mongrel2.org/ http://mongrel2.org/) was designed around it.
- ak217 15y agoI'm really interested in this for building simple API endpoints. I tried a bunch of WSGI servers and lightweight frameworks to serve stuff on them, but realized that there is no way to support chunked request content encoding with WSGI (the WSGI spec is not compatible with it, so WSGI can't support HTTP/1.1). Hopefully Brubeck is good, please let us know if there's anything else worth checking out!
- anthonyb 15y agoEventlet seems to support it: http://blog.eventlet.net/2010/02/12/scalable-wsgi-compatible-websockets/ http://blog.eventlet.net/2010/02/12/scalable-wsgi-compatible...
- jemeshsu 15y agoPython's greenlet libraries such as Gevent & eventlet makes websocket type of applications possible. It is not difficult to add in websocket support into WSGI frameworks such as Pyramid/Flask. One example http://blog.abourget.net/2011/3/17/new-and-hot-part-4-pyramid-socket-io-gevent/ http://blog.abourget.net/2011/3/17/new-and-hot-part-4-pyrami.... You can have both WSGI and websocket in the same stack.
- espeed 15y agoYou can, but monkey patching is not always ideal (https://www.google.com/search?q=gevent+monkey+patch+issues https://www.google.com/search?q=gevent+monkey+patch+issues).
- jemeshsu 15y agoSupport for websocket is not yet fully baked into Mongrel2. The handshake etc needs to be done on the handler side. So gevent solution is a better bet at the moment. The alternative is to have a separate Tornado/Node.js to handle websocket alongside Django/Pyramid app. Mongrel2 does look promising, although it seems zedshaw is pretty resource tide at the moment.
- irahul 15y agoDon't run on your whole app on gevent, but only the part which needs streaming/long poll. By decreasing the surface area, you can pin point the bugs arising due to monkey patching.
- wycats 15y agoDoesn't making a new X because it's easy violate the "There should be one-- and preferably only one --obvious way to do it" rule? From the way the Python community talks about its strengths, I'd expect there to be pressure against creating a new X just because you can.
- anthonyb 15y agoLanguage features and third party libraries are different things though.
- nerfhammer 15y agoarguably, arguably all the 'interfaces' needed to make code do a web site end up being a domain-specific language
- reuser 15y ago"Arguably" every API ever written is a domain-specific language.
- fennecfoxen 15y agoRumor (and by rumor I mean a couple of opinionated coworkers) says: the Python community has a lot of cases of "This project didn't have the feature I needed and has a couple of problems, so I went and wrote a whole new one with a different set of problems." By contrast, the Ruby community settles down on one, maybe two things as the primary way to do it. This article lends weight to the rumor.
- anthonyb 15y agoIt works the way that most open source third party libraries do: There'll initially be some hacked together stuff, then a couple of contenders will emerge, copying each other's features. After the dust has settled there'll be a few decent libraries. Examples that I can think of off the top of my head are freshen/lettuce/behave, there were also a bunch of XML parsers leading into elementree (which is now in the standard library). In Ruby you have Rails, Sinatra, and a couple of other frameworks, as well as Mongrel2 and friends to run it all.
- cd34 15y agoNote that the original article has a publish date of 2006-09-05.
- anthonyb 15y agoThis article would date back to around the time of Turbogears, CherryPy, etc. before Django became the 'default' solution.
- jordanmessina 15y agoAnd uses python 2.4
- sekou 15y agoIt may be easy to link together well developed Python libraries for web development, I think it's one of the benefits of working in Python, but full stack frameworks like Django that provide a somewhat unified API exist at least in my mind on a different level of framework. I think there is a spectrum of complexity represented in the list of frameworks linked by the author, and the word "framework" is used to describe a lot of different kinds of situations.
- jrockway 15y agoBecause Python's motto is "There's more than one way to do it."
- nerfhammer 15y agoyou forgot to enclose your answer in a <sardonic> tag
- reuser 15y agoPeople writing tools to learn, or because the existing ones didn't suit their needs or tastes, occurs in every language and is very different from Perl-style "more than one way to do it". It's ridiculous to act like the mere existence of multiple independent projects for one task is some kind of searing indictment of the "one obvious way" principle in language and API design.
- jrockway 15y agoI've never actually noticed "one obvious way". There are a couple ways to do almost everything in Python; loops or map, Twisted or threads, unittest2 or nose, and so on. I like Python, but human nature pushes everything towards "there are many ways to do it", and humans have influenced the direction of Python. I prefer Perl's approach of embracing more than one way to do things. I don't really want there to be 8 ways to do one thing, but it's just a more realistic outlook. You go into Perl knowing that you are going to have to try a bunch of different things to see what fits your mental model, instead of being told what to do. (I used Python at a Bank where they wrote their own style guide, completely different from the standard Python style guide. WTF? Humans have a way of ruining everything.) Ironically, many things in Perl have converged into "One Obvious Way"; PSGI/Plack for web frameworks, Test::Builder for unit tests, and so on.
- irahul 15y ago> There are a couple ways to do almost everything in Python; loops or map, Twisted or threads, unittest2 or nose, and so on There are always more than 1 ways to do something, but Python tries to be directive towards the recommended way for the core. For the given snippet, using reduce for loops is frowned upon; nothing is stopping you from doing it, but the general opinion is you shouldn't do it. I think that counts as there being an obvious way. def pipe(val, fns): return reduce(lambda val, fn: fn(val), fns, val) def pipe2(val, fns): for fn in fns: val = fn(val) return val fns = [lambda x: x + 1, lambda x: x * x] print pipe(5, fns) print pipe2(5, fns) As far as maps and list comprehension go, that isn't clear-cut but people incline towards comprehensions. <nitpick> Twisted(reactors) and threads implement two different things which serve different purposes, and unittest2 is a lib while nose is a test runner. </nitpick> That said, there is always going to be many ways to do something, but it helps if the core tries to stick with a uniform way to do things.
- cbs 15y agoIf the paradox of choice is making the options an uncomfortable situation for you, just write down the top 6 and roll a die. Problem fucking solved. Or act like a grown up and evaluate your options.
- yuest 15y agoNow, nodejs may be a better choice.
- hashfold 15y agobecause one can't solve all the specific use cases people have. or may be Python is not so generic to help solve these use cases.
- eli_gottlieb 15y agoBecause nobody wants to admit that web applications are mostly just a bad idea.
- irahul 15y agoWhile we are at the topic of Python web frameworks, I seriously like Flask's design better than django's. True that django came out before SQLAlchemy or Jinja2 became popular/existed, but I would have loved it had they re-factored. Django is great, with good re-usable components, but I like Jinja2 more than Django's templating. The argument for SQLAlchemy is more on the lines of I would prefer a standard ORM compared to everyone baking their own. SQLAlchemy used to be verbose, but the declarative extension now takes care of it. Other things I like about flask are explicit app object, and context locals.
- BerislavLopac 15y agoFirst, it's quite simple to replace Django's templating engine with Jinja. And second, Django's ORM isn't quite the equivalent of SQLAlchemy; the latter is supposed to be a true universal ORM, while the former is more limited, but focusing on the most important parts for a Web app.
- irahul 15y ago> First, it's quite simple to replace Django's templating engine with Jinja. Yes, it is. But most of the applications are tightly coupled with Django's ORM(auth, for eg, which I use very frequently), and in the end, I end up maintaining two types of templates which I don't like. > And second, Django's ORM isn't quite the equivalent of SQLAlchemy; No, it isn't. But SQLAlchemy does what django's orm does, and then some. I would prefer a compartmentalized model, where a web framework doesn't implement templating or ORM, provided a robust solution exists. The templating engine and ORM should be independent libs, and the web framework should glue them together, possibly adding a declarative layer above them(render_to_response, declarative ORM etc).
- rlander 15y agoTotally agree with you on this. I think Flask is Django done right and I've been beating that drum for quite some time (see, for example, my comments on the settings file [1]). The core devs claim that SQLAlchemy and Jinja weren't around at the time Django was developed, and that's fine. But in 2012, Jinja2 and SQLAlchemy are clearly better alternatives to Django's defaults. So why not incorporate them? Django doesn't even have first class support for Jinja2 templates, let alone the python HAML variants. What's ironic is that a few years ago Django was known for being loosely coupled when compared to Rails, which was considered monolithic ("my way or the highway"). Nowadays Rails is the flexible framework, allowing for different ORMs and templating systems, while Django is now the monolithic framework. Don't get me wrong, I love stability. But when a great percentage of developers are using hacks to get around the default configuration system and to support excellent external libraries like Jinja2 and SQLALchemy, something is very wrong. [1] http://news.ycombinator.com/item?id=3556929 http://news.ycombinator.com/item?id=3556929
- 6ren 15y agokid seems to be down: http://www.kid-templating.org/ http://www.kid-templating.org/ Here's wiki on it: http://en.wikipedia.org/wiki/Kid_%28templating_language%29 http://en.wikipedia.org/wiki/Kid_%28templating_language%29
- SimHacker 15y agoGenshi is a much better replacement for Kid. http://genshi.edgewall.org/ http://genshi.edgewall.org/
- dspillett 15y agoBecause writing your own web framework seems to be a "rite of passage" for Python programmers, or did around the time that article was first written. The same thing is happening with node.js right now.
- rlander 15y agoThis post is from 2006. Here's a more recent article in the same "DIY Python Framework" spirit, which is longer but quite good: http://docs.webob.org/en/latest/do-it-yourself.html http://docs.webob.org/en/latest/do-it-yourself.html
- SimHacker 15y agoGenshi is a much better replacement for Kid. http://genshi.edgewall.org/ http://genshi.edgewall.org/
- NathanRice 15y agoA lot of people will make snide remarks when someone says they are creating their own framework, but obviously if someone has evaluated the existing frameworks and still decides to do it, there is an unscratched itch. A lot of people who aren't happy with the larger monolithic frameworks have adopted flask (myself included) as a simple base to build more interesting things on. There are a number of things no framework I have yet run into does well: 1. Unification of client side and server side events. With options like Backbone or (ugh) ExtJS on the client side, there is a lot to be gained from a coupled event subsystem over websockets, or via server sent events. 2. A true viewmodel based page composition framework, where components are abstract view elements with data bindings on the server side, which then have associated renderers for the output to the client. I've played with both of these, and found them to have a lot of advantages over standard template + ajax + callbacks style of design, though creating a library for others is a lot more work than hacking something for yourself :)
- dignan 15y agoHe doesn't build a framework. He uses libraries to create a web application. This is also an article from 2006.