Dumb-as-rocks WSGI serving using standard library

B

Ben Finney

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?
 
D

Damjan

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.

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?

There's no WSGI http server in the std lib as of Python 2.4.

Paste[1] provides one, wsgiref[2] (probably will be included in Python 2.5)
provides a SimpleHTTPServer and CGI based WSGI servers.
There's also WSGIUtils[3] that provides that.

[1] http://pythonpaste.org/
[2] http://svn.eby-sarna.com/wsgiref/
http://www.artima.com/weblogs/viewpost.jsp?thread=158191
[3] http://www.owlfish.com/software/wsgiutils/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top