Home > Articles > Programming > Python

Python Web Programming: Web Application Frameworks

  • Print
  • + Share This
Review the classic web server architecture and the roles that Python can play under such a regime, and look at some of the possible pure Python architectures for web systems.
This sample chapter is excerpted from Python Web Programming, by Steve Holden.
This chapter is from the book

This chapter is from the book

If you don't like to do your own plumbing, you send for a plumber. If you don't like building web systems from the ground up, you use frameworks. Python's natural affinity for the web has been exploited many times to build web-system frameworks, with varying degrees of success, and the results are often freely available through the generosity of their authors. Some frameworks assume that you are working with a classic web server. Others give you more freedom by concentrating mostly on HTML generation, but even these tools often include the capability to intermingle Python and output text for more flexibility in content generation.

In this chapter, you will review the classic web server architecture, and the roles that Python can play under such a regime. Next you will go on to look at some of the possible pure Python architectures for web systems. Finally, you will meet Xitami, a lightweight web server with the capability to interact with long-running processes. Although this may not cover the whole range of server architectures available, it is a sufficiently diverse range to give you a good idea of the possibilities.

Along the way, you will learn some things that will help in many different architectural contexts. The task of interacting with web clients has many common features no matter what the eventual architecture. You also will learn an easy way to integrate databases with Python, allowing you to address all database columns as attributes of the rows that contain them. The chapter concludes with a look at HTML generation and a glance at intercomponent communications. At that stage, you will be ready to tackle the kind of problem that webs are being built to solve every day.

Information Sources

It is difficult to keep track of Python web toolkits. Cameron Laird maintains useful information on web uses of Python at http://starbase.neosoft.com/~claird/comp.lang.python/web_python.html/, and Paul Boddie makes a good survey of the field at http://www.paul.boddie.net/Python/web_modules.html. Both of these resources appear to be actively maintained at the time of writing.

Most publicly available web servers come with copious documentation. The Python code you will find comes with documentation of varying quality, ranging from "thin" to "excellent," but sadly the former tends to outweigh the latter. One of the current shortcomings of the open-source world is that more people want to write code than document it. This is a real pity, when you consider that good documentation usually increases the likelihood of software being reused by others.

The software world has always undervalued documentation (at least from the pragmatic point of view of not producing enough). The Python language is a model of its type, and although the documentation may not be perfect, Fred Drake does a very good job of ensuring that it is both useful and consistent, as anyone can see at http://www.python.org/doc/current/. Ka-Ping Yee presents another model site at http://web.pydoc.org/ and simultaneously manages to demonstrate the value of his pydoc module. What follows is an eclectic summary of available web frameworks of various types, all of which accommodate Python somehow. The exclusion of a particular framework from this chapter does not imply a value judgment about that framework. There really are far too many Python web frameworks for a single chapter, so I have tried to choose a representative sample that gives a flavor of the current state of the art.

  • + Share This
  • 🔖 Save To Your Account