What Makes Pylons Stand Out As a Web Framework
After 6 release candidates, Pylons 0.9.7 final has been released. Big congrats to all developers. Although it's just a point release, I think this is a huge milestone for Pylons for one reason: It has proper documentation! I've been using both Pylons and Django for several web applications and Pylons' old docs were sparse and hard to navigate. This didn't stop me from digging in and playing around with the framework but for a project to really reach a wide audience it needs well-organized, readable documentation. I can think of many well designed, solid programming tools that have failed because, simply, their docs were not readable. There is a difference between having comprehensive documentation and having documentation that is readable. Django got this right from day one.
As a Pylons user, I'd like to point out a few reasons why I like it and some reasons I don't. It's not meant as a fair comparison to Django, but Django is the only other web framework I know pretty well so it is my point of reference.
Likes:
- It's a "hacker's" framework.
- When you install it, Pylons generates just enough code to expose its operational mechanisms but not too much code to make upgrading hard. In other words, the core of Pylons is in the pylons module yet all that initialization and request handling code is exposed to you in your own application.
- Pylons is just a wrapper around lots of other modules maintained by the community.
- Just like Python itself ;) This is an advantage to me because the PyPI has a lot of neat stuff and it's easier to create, test, and maintain a small component that does one thing well than it is to fit that into a large framework that does everything.
- In the critique I've seen of this feature, I think mostly it was due to a misunderstanding of the setuptools module (and easy_install script), which provides utilities for handling large amounts of dependencies. There is already a nice alternative to easy_install which allows for flat installation of dependencies (no egg directories) and more, called pip.
- Wrapping up lots of other powerful tools makes for a powerful web framework. Here are just a few of what I think are excellent add-ons to Pylons (or any web framework) :
- WSGI Middleware
- At some point in the past I might have marked this as a dislike. WSGI is hard to understand. Admit it, it will make your brain bleed! But once you get it, it is very clever. I have written a lot of custom middleware to do things like intercept URLs to stub out web services, add static file handling for development, and provide custom error handling. Most of Pylons is implemented as middleware so you can literally strip it down to the core if you need extra speed and simplicity. Also, WebOb provides utilities that make WSGI simpler to implement.
Dislikes:
Short variable names and from yourapp.lib.base *.UPDATE: I just found out the import * and short variable names c and g are no longer the defaults in 0.9.7.- Sharing applications?
- I admit I haven't tried to share applications in a Pylons app the way I have in Django. I suppose this can be done in Pylons simply with middleware? Anyway, Django seems to have thought about this problem a little more and makes it easy to "glue together" multiple applications so that their URL spaces can merge effectively.
- Routes
- I don't like Rails-style routes, the default dispatching middleware for Pylons. I much prefer Django's URL patterns which are more pythonic. OK! I guess that means I need to write a Django-style URL middleware :) Obviously it doesn't bother me too much because I have not written my own. UPDATE: In the comments, L.C. Rees posted a link middleware that does this: urlrelay. Cool!
As a disclaimer I should point out that I am one of those developers who likes to build low level tools. I certainly reuse existing components when possible but building small tools that do one thing and do it well is fun because it's easy. Pylons fosters this approach to software. Not all developers are like this and I'd say, overall, Django probably offers more of a "batteries included" feeling.

Re: What Makes Pylons Stand Out As a Web Framework
posted by Andrew Bloom on Monday Feb 23rd, 2009 at 5:05p.m.
In your dislikes you mention routing. As a Rails dev I must say one of the things I love is the simple declarative routing mechanism. Looking at the Django docs scares me. Are you really saying you prefer to write a file full of regexp's instead?
Re: What Makes Pylons Stand Out As a Web Framework
posted by Eric Larson on Monday Feb 23rd, 2009 at 6:51p.m.
@Andrew Bloom
In some ways I agree that the simplicity of Routes is nice, but that the same time, when URLs define an actual API, simplicity becomes a negative. For example, if you are doing content negotiation via simple extension and provide a default without an extension, then you'd want to be particular about when a trailing slash needs to be appended and 303s are returned. This is something of a contrived example, but a small convenience can backfire in some cases.
I don't say this to bash Routes either. I've used it and other dispatchers happily, but I've also ran into cases where I would have preferred a simple regex and lose the magic.
Re: What Makes Pylons Stand Out As a Web Framework
posted by Eric Larson on Monday Feb 23rd, 2009 at 6:52p.m.
@Andrew Bloom
In some ways I agree that the simplicity of Routes is nice, but that the same time, when URLs define an actual API, simplicity becomes a negative. For example, if you are doing content negotiation via simple extension and provide a default without an extension, then you'd want to be particular about when a trailing slash needs to be appended and 303s are returned. This is something of a contrived example, but a small convenience can backfire in some cases.
I don't say this to bash Routes either. I've used it and other dispatchers happily, but I've also ran into cases where I would have preferred a simple regex and lose the magic.
Re: What Makes Pylons Stand Out As a Web Framework
posted by L.C. Rees on Monday Feb 23rd, 2009 at 8:05p.m.
Since I'm using Pylons side by side with Django, I agree with the argument that Pylons could use a more visible app sharing framework. I'd like one that used Routes' syntax, since I find it slightly more attractive than writing regexs. That being said, I extracted Django's dispatcher into a piece of WSGI middleware a few years back and have kept it up to date. It can dispatch on regexes and glob patterns. I know Kevin Dangoor's using it in Bespin, a new project from Mozilla Labs.
http://pypi.python.org/pypi/urlrelay/
Re: What Makes Pylons Stand Out As a Web Framework
posted by Kumar McMillan on Monday Feb 23rd, 2009 at 10:15p.m.
@L.C. Rees : this rocks! I'm glad you posted the link; I didn't know about it. I like the regex style because you can look at the URL mappings and you know exactly what's happening, you don't have to read the docs.
When I was learning Routes I found everything very unintuitive. It is clean and simple but it is an abstraction that I had to learn, like another language. It wasn't hard to learn but, for example, one time I needed to route to a controller in a submodule. Was it controller='submodule.the_controller' or was it controller='submodule/the_controller' ? There should be an intuitive answer to a question like that.
Re: What Makes Pylons Stand Out As a Web Framework
posted by Ben Bangert on Tuesday Feb 24th, 2009 at 1:57a.m.
By the way, it seems Django is quickly growing a newfound fondness for one-letter variables:
http://docs.djangoproject.com/en/dev/topics/db/queries/#query-expressions
And I believe there is a Q() around as well.
Re: What Makes Pylons Stand Out As a Web Framework
posted by Ids on Tuesday Feb 24th, 2009 at 2:57a.m.
The WebOb do-it-yourself framework has a nice example of a URL dispatcher with a clean syntax and (optionally) using regex. Have a look at:
http://pythonpaste.org/webob/do-it-yourself.html#routing
Re: What Makes Pylons Stand Out As a Web Framework
posted by Kumar McMillan on Tuesday Feb 24th, 2009 at 8:36a.m.
Ben, re: Django one-letter variables, that is unfortunate.
Re: What Makes Pylons Stand Out As a Web Framework
posted by jmoiron on Tuesday Feb 24th, 2009 at 10:03p.m.
If you like django's url routing, you might want to try Selector from luke arno:
http://lukearno.com/projects/selector/
I prefer using pre-built patterns to use rather than using raw regex everywhere, as I find them much more usable. Nice thing is you can still fall back to regex when you need to do something weird. I've ported this module to use w/ django's url routing; ymmv:
http://dev.jmoiron.net/hg/jmoiron.net/file/tip/saudade/common/urls.py
As for 1 letter var names, Q() in django's orm is a query object, used most often to build queries that would require SQL's OR. While I don't particularly like django's orm, I don't mind 1 letter variable names if 1. they are central to what the library does and 2. their arguments are more descriptive of what they're doing than the full name would be. Like $ in prototype/jQuery, or translation routines that are frequently renamed to "_" in C applications.
Re: What Makes Pylons Stand Out As a Web Framework
posted by .:. brainsik on Monday Mar 2nd, 2009 at 2:19p.m.
TurboGears has rewritten their API to sit on top of Pylons:
http://www.turbogears.org/2.0/docs/main/WhatsNew.html
Basically, it's Pylons with all the batteries included.
The team I'm working with was completely sold on using Pylons because we wanted to use specific components, like SQLAlchemy and Genshi. However, TurboGears has picked the components we wanted to use so now we are seriously considering using it instead. I've had very good experiences in the #turbogears channel.
Re: What Makes Pylons Stand Out As a Web Framework
posted by Noah Gift on Tuesday Mar 10th, 2009 at 5:34a.m.
@brainsik Maybe they will merge "officially" at PyCon. Wouldn't that be sweet. If they could get Armin to join the team too, that would be the dream team...
Re: What Makes Pylons Stand Out As a Web Framework
posted by Kumar McMillan on Tuesday Mar 10th, 2009 at 10:54a.m.
Actually, I think it makes sense for them to remain separate. It allows Pylons to focus on being a "core" webapp layer and for TurboGears to focus on providing all the widgets and extra convenience for routing, python-code configs, an administrative command line tool, etc.
Re: What Makes Pylons Stand Out As a Web Framework
posted by Noah Gift on Tuesday Mar 10th, 2009 at 2:58p.m.
@Kumar: I like the whole Kubuntu/Ubuntu think Mike Orr talks about. I think that is a great way to describe Turbogears and Pylons. Just different flavors off the same code base.