Although Python is not as prevalent as, say, PHP as a language for Web applications, Python nevertheless has much to recommend it in that effort. It is a dynamic, interpreted language, as is PHP, and therefore encourages iterative, exploratory development. Programming purists could point to the fact that object orientation was designed into Python from its very beginnings, rather than being retrofitted to the language at a later point in its life.
Language design considerations aside, the capabilities embodied in Python's standard libraries are impressive. Python even installs with its own Web server. In addition, Python boasts plenty of free database libraries, numerous free Web page template systems, and even libraries for interfacing with your favorite Web server, all ready to download and apply to your next Web application project.
[ Also on InfoWorld: "InfoWorld review: Nine fine Python development tools" | Neil McAllister reveals the most dangerous programming mistakes. | Get software development news and insights from InfoWorld's Developer World newsletter. ]
Of course, you don't need to do all that work. The engineers of these capable and diverse Python-based Web frameworks have done it all for you.
In the following pages, we review six Web application frameworks for the Python Web developer. These are by no means the only Python Web frameworks available, but represent a broad sampling of the possibilities. No matter what your needs or leanings as a Python developer might be, one of these frameworks promises to be a good fit.
They include Zope 2, the proud descendant of one of the longest-established Web server frameworks in any language; Web.py, a low-abstraction framework that provides only the essentials for Web development; Web2py, a higher-level framework that provides its own Web-based integrated development environment; Pyramid, a flexible new offering from the group that produced the popular Pylons framework; the popular and highly regarded Django framework; and CubicWeb, with which you can build not just Web applications but semantic Web applications.
Python Web frameworks: Light, heavy, and in betweenZope 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.
Python Web frameworks: Min or max?If you prefer a framework that puts the minimum between you and the Web, then Web.py will be your best choice. On the other hand, if you like wizards guiding you along the way, then you may prefer Web2py. CubicWeb is an excellent choice if your data comes from disparate sources. If your website's structure is data driven, then have a look at Pyramid or Zope 2. In addition, Zope 2 and Django are solid all-around choices, both having stood the test of time.
But these are only general suggestions. It's not the case that any particular Python Web framework is at a significant disadvantage to the others. As usual, the choice is highly subjective. You will find zealots for each product, and every zealot is able to present rational reasons why their chosen framework is superior.
Naturally, the current discussion paints only an overview. For the finer details, follow the links in the table below and plunge into the individual reviews.
This article, "Pillars of Python: Six Python Web frameworks compared," was originally published at InfoWorld.com. Follow the latest developments in application development and Python at InfoWorld.com. For the latest developments in business technology news, follow InfoWorld.com on Twitter.
Read more about application development in InfoWorld's Application Development Channel.
This story, "Pillars of Python: Six Python Web frameworks compared" was originally published by InfoWorld.