XML.com: XML From the Inside Out
oreilly.comSafari Bookshelf.Conferences.

advertisement

Introducing WSGI: Python's Secret Web Weapon, Part Two
by James Gardner | Pages: 1, 2, 3

Configuration

When the Web Server Gateway Interface was being drawn up, there were a number of discussions about how best to deploy a finished application with middleware. Clearly developers couldn't expect non-technical users to directly modify the middleware chains themselves. The most widely adopted solution is to use PasteDeploy. Users configure a config file in a familiar INI-style format, and the desired application--with any necessary middleware--is created by PasteDeploy from that file. PasteDeploy is used like this:

    from paste.deploy import loadapp
    application = loadapp('config:/path/to/config.ini')

The configuration file can be used to specify server settings, including middleware, and even combine multiple WSGI applications together into a composite application. All the options are well documented on the PasteDeploy site.

The Many Frameworks Problem Revisited

At the start of Part I of this article, we looked at how the WSGI was created to help solve the fragmentation of the Python web community. The WSGI specification also had wider ambitions. PEP 333 states:

"If middleware can be both simple and robust, and WSGI is widely available in servers and frameworks, it allows for the possibility of an entirely new kind of Python web application framework: one consisting of loosely coupled WSGI middleware components. Indeed, existing framework authors may even choose to refactor their frameworks' existing services to be provided in this way, becoming more like libraries used with WSGI, and less like monolithic frameworks. This would then allow application developers to choose "best-of-breed" components for specific functionality, rather than having to commit to all the pros and cons of a single framework."

With today's powerful middleware, this vision is fast becoming a reality. Emerging projects such as Clever Harold provide just such a framework of loosely-coupled middleware components. Projects such as Pylons go further still, providing a ready-made configuration of WSGI middleware. We have also seen existing projects like Myghty refactored to work better with WSGI configurations.

The WSGI has shifted the point of reuse from the framework itself to individual middleware components. While developers can still create their own solutions to web development problems, as long as they're creating, using, and improving middleware components, the whole Python community now benefits.

I hope this article has demonstrated some of the power of WSGI middleware and will encourage you to make use of the specification and the various projects that already implement it. Here are some useful places to start if you wish to learn more about WSGI programming.