Pillars of Python: Six Python Web frameworks compared

CubicWeb, Django, Pyramid, Web.py, Web2py, and Zope 2 give Python-savvy Web application developers powerful and diverse options

Page 2 of 3

Python Web frameworks: Light, heavy, and in between
Zope 2 is a descendant of Zope, the great-granddaddy of all Python Web application tools and an important branch in the Python family tree. Zope 2's ancestry, then, goes back to the mid-1990s, and Zope's continued popularity is testament to its solidity. Consequently, one huge advantage to choosing Zope 2 is that you can call on 15 years of code development and documentation.

Zope 2's "object publishing" system fits well into an object-oriented development mind-set and mitigates somewhat the learning curve you'd have to climb if you picked a framework that exposes your application to more of the more painful aspects of Web development. Zope 2 does present a formidable learning curve of its own -- but you'll at least enjoy the stability that a 15-year pedigree confers.

The Web2py framework is an abstraction paradise. Databases hide behind a Database Abstraction Layer (DAL). Web2py's rendering system will try to find a view that -- depending on context -- displays an object in HTML, XML, JSON, or any of the half-dozen protocols the framework supports. Intelligently crafted by a professor of computer science, Web2py's template system actually lets you use Python as an HTML-embeddable scripting language. Falling somewhere between the all-encompassing world of Zope 2 and the minimalism of Pyramid, Web2py may well be the best framework for Python-savvy developers to enter the world of framework-based Web application development.

The philosophy of Web.py -- a minimalist framework -- is not to abstract away the details of interacting with the Web, but to make that interaction easier. As a result, you'll find yourself writing HTTP GET function handlers directly. Likewise, the Web.py database system does not abstract away SQL; rather than hide the fact that you're querying a database, it hides the details of working with different databases. Web.py does define a template language, which -- like that of Web2py -- lets you embed arbitrary Python code in a Web page. Web.py is ideal if you're already familiar with building Web applications (perhaps you once wrote CGI-based applications). You'll get started quickly with Web.py, but you'll have to rely on your own wits to go beyond simple Web applications.

Pyramid is also minimalist Web framework, not so much in its capability as its philosophy. It makes no assertion concerning the back-end database you should use, nor does it foist a particular template system on the developer. (Currently, Pyramid supports two, though Pyramid itself tries to remain agnostic regarding the choice.) If Pyramid has any blemishes, it is the quirky terminology with which its documentation describes the framework. In addition, its laissez-faire attitude can leave you wondering precisely how to proceed to accomplish a particular task -- and, when you manage to accomplish that task, whether your solution was the best. For example, there are two separate means of determining how your application will handle a given URL: the well-known URL-mapping mechanism and something called "traversal" (which you will need to read the documentation to figure out). So, with Pyramid, you purchase flexibility at the cost of turning yourself into something of an explorer.

Django is a mature and highly regarded Web framework that assumes you know Python well. Its libraries provide a good selection of the must-have capabilities for accelerating Web application development: an object-relational mapper so that you don't have to write your own RDBMS interface code, a template system so that you don't have to wrestle with marrying active Python content to static HTML content on a Web page, an administrative interface so that you can easily access your site's back-end data (as well as easily manage website users and permissions), and so on. You should expect to spend a stretch learning Django's API, but the time you put into Django is well worth it. It's a rich environment with much to recommend it.

CubicWeb touts itself as not merely a Web development framework, but a semantic Web development framework. This distinction becomes clear when you discover that a CubicWeb application's interaction with a database is performed through RQL (Relation Query Language), a query language similar to the W3C's SPARQL for RDF. CubicWeb's libraries translate RQL queries to SQL or XML or LDAP or whatever protocol is appropriate for the data store being accessed. CubicWeb is probably the most difficult framework in this review to grasp. The difficulty is not only on account of the jargon you must learn, but also because constructing a CubicWeb application entails lashing together modules (called cubes) into a final structure -- a process that will be foreign to neophytes. Once you get the hang of it, however, CubicWeb does permit rapid development. A basic model schema is enough to get an application off the ground, and CubicWeb's agile characteristics let you grow the application in iterative fashion.

| 1 2 3 Page 2
From CIO: 8 Free Online Courses to Grow Your Tech Skills
View Comments
Join the discussion
Be the first to comment on this article. Our Commenting Policies