Dumb-as-rocks WSGI serving using standard library

Ben Finney bignose+hates-spam at benfinney.id.au
Mon May 22 04:18:34 EDT 2006


Howdy all,

I'm trying to implement some new functionality for an existing PHP web
application. Rather than writing a whole lot of stuff in PHP, and
looking toward a future when more of the application can be rewritten
more sanely, I'd like to write a Python program that generates the
content and serves it up to the existing application via HTTP.


The existing architecture is as expected:

  web client <--(HTTP)--> existing app

with the existing app also talking to a database.

The new functionality involves generating a PDF document from input
parameters and returning it to the browser.  Rather than nestle this
into the existing PHP, I'd like the existing app to simply make an
HTTP request to a single-purpose application server written in Python
which generates the content and serves it back as the response body.

This would insert into the above architecture behind the existing
application:

  existing app <--(HTTP)--> request server <--(WSGI)--> content generator

The bulk of the new functionality would be in the generation of the
content from the input parameters.

The request server would run locally on the machine, listening for
HTTP requests and invoking the content generator via WSGI; the
generated document would simply be served back as the HTTP response
body.

The existing application would then just need to gather the input
parameters needed, feed them in an HTTP request to the request server,
and feed back the response to the web client.


I can see how writing the content generator to talk WSGI would be
beneficial: the application can be re-used in other application
contexts. The WSGI protocol is easy to follow.

What I can't find is a simple recipe to serve a WSGI application with
a dumb-as-rocks HTTP server, just using the standard Python library.

The standard library includes BaseHTTPServer, which as far as I can
tell doesn't know anything about WSGI.

The don't seem to be any recipes posted to the Python Cookbook
<URL:http://aspn.activestate.com/ASPN/Python/Cookbook/> with "wsgi" in
them.

Everything else that I can find leads to dependencies I don't want for
flexibility I don't need: cherrypy, paste, et al.

Any suggestions for how to serve up a simple WSGI application with
just the standard library?

-- 
 \     "A cynic is a man who, when he smells flowers, looks around for |
  `\                                   a coffin."  -- Henry L. Mencken |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list