Python has a good reputation for tasks like systems programming, network programming, and scripting, but Python for the web is becoming red hot. Part of this has to do with the very popular web framework Django, that was developed at a newspaper to help quickly create Content Management Sites. . Another reason is that Google App Engine–Google’s Cloud Computing offering for developers–only exposes a Python API.

If you are new to Python Web Development, then I’d recommend Django, as it is ideal for building CMS-type applications, social networking websites, and blogs. On the other hand, If you want a hacker’s framework, you might want to give Pylons a look.

Please note: By hacker, I am referring to the kind of hacker Eric Raymond refers to when he writes, “Becoming a hacker will take intelligence, practice, dedication, and hard work. Therefore, you have to learn to distrust attitude and respect competence of every kind. Hackers won’t let posers waste their time, but they worship competence — especially competence at hacking, but competence at anything is valued.”

Ok, so what problem does a hacker’s framework solve that a framework like Django doesn’t? According to some of the Pylons developers, their framework is geared to solve 80/20 problems. Most people—80% of people–want to build blogs, and CMS-type applications. And for that 80%, Django works just great. Of course, the other 20% is where Pylons comes in to play as a “hacker’s framework.”

Philosophically, Pylons is quite different. Pylons abstracts third-party libraries, such as WebOb, Mako, SQLAlchemy, Routes, and Beaker, to make a “hacker’s brew.” These libraries are loosely coupled–not in a internet marketing sense, but in a computer science sense. This means that it is quite easy to swap out the ORM, or templates, or URL routing, and create some alternate development stack. Note, that another hacker’s framework, Werkzeug, also follows a similar philosophy (See the references for more details).

What does a hacker’s framework buy you? Well, it allows you to change your web development paradigm. You no longer need to think in terms of what you can do with the choices defined by a framework. It allows the experienced developer to transcend this potential trap, and think about the actual problem at hand. For example, it may be more productive to start by using SQLAlchemy (the object-relational mapper) by itself.

Once the data model is working as expected, then it could turn into a command line tool, then potentially a WXPython application instead of a web application. Hacker’s frameworks let the developer decide what is best for them at any given situation. Additionally, by focusing on loosely coupling the “best of breed” components, it allows the user of a “hacker” framework, to use literally, the best component for the job. This extra power can come in handy with more complex problems.

Setup

In this article we dive into building an AJAX blog using Pylons. We cheat by using the bookmark tagging site, Del.icio.us as an admin interface that we don’t have to write. When a user creates content on Delicious, the Google AJAX feed API allows that content to be displayed locally on the web page. This is one of the most efficient type of blog that someone can create, as it reuses existing code, APIs, and services.

Building a Pylons AJAX blog

To get started you can download the whole example and run it, or you can follow the steps below. Note that in version control, each step is a separate Pylons project.

Summary

In this article we explored some of the ideas behind Pylons, a hacker’s framework, and how it differs from a philosophy framework, like Django or Ruby on Rails. Note by philosophy framework, I am referring to how a developer must abide by the opinions of the developer of the framework, such as in the case of Django templates where a developer is handcuffed against running code in the template. For example, their idea of perfection might be different then yours. Some people refer to this as being an “opinionated” framework. Each one has its purpose, and place. If you just want to make a Content Management website MS website for your American Literature class project, then maybe a hacker’s framework isn’t suited for you or the project, as it is overkill. On the other hand, if you want maximum flexibility, power, (and, of course, “street cred”) you might give a hacker’s framework a try.

Finally, we got into making an actual Pylons AJAX blog that used Delicious to suck in feeds. This was accomplished by reusing code via the Google AJAX Feed API. Ok, enough talk, get to hacking….

Extra Credit: If you are interested diving into a more complex Pylons project template on your own take a look at this source code url. Jonathan Ellis, a Python hacker known for his work with SQLAlchemy, has donated a do-it-yourself tutorial on using FormAlchemy to create a simple blog in Pylons. I have included a link to his original article on the topic in the reference section.

About the author

Noah Gift is the co-author of “Python For Unix and Linux” by O’Reilly, and “Google App Engine in Action” by Manning. He is an author, speaker, consultant, and community leader, writing for publications such as IBM Developerworks, Red Hat Magazine, O’Reilly, Manning and MacTech. He has a Master’s degree in CIS from Cal State Los Angeles, B.S. in Nutritional Science from Cal Poly San Luis Obispo, is an Apple and LPI certified sysadmin, and has worked at companies such as, Caltech, Disney Feature Animation, Sony Imageworks, Turner Studios, and–most recently–WetaDigital.

6 responses to “Introducing Pylons: A hacker’s web framework”

This post is very great introduction
using pylons and it position on the
web arena to anybody, even for
dummies.
I wonder, can I use python to create
web application, like healthcare
infomation system ?

ITG Digital Info is a modern organization providing world class innovative solutions to small, mid-size and corporate organizations and businesses. We provide global customers the optimum advantages of outsourcing in terms of cost, quality and quick turnaround time. Our offshore outsourcing services providing customized business propositions offer immense value to customers thereby building enduring customer partnerships. Our core value constitutes employing integrity at all times and being fair to our employees, customers, vendors, media, community and all other stakeholders. http://www.itginfo.com

…”get buzzword compliant”…
I’m a grumpy old fuddyduddy. I don’t think real hackers ever get buzzword compliant. Just ask Dennis Ritchie. I think he would see this “mashup” of passing objects around between environments as being equivalent to touching yourself behind the curtains.