Use the mod_wsgi plugin for Apache.
You can do this to see how an existing script can be converted to a WSGI application. This is a starting point to show how the WSGI works.
import sys def myWSGIApp( environ, start_response ): with file( "temp", "w" ) as output: sys.stdout= output execfile( "some script.py" ) sys.stdout= __stdout__ status = '200 OK' headers = [('Content-type', 'text/plain')] start_response(status, headers) result= file( "temp", "r" ) return result
Note that you can easily rewrite your scripts to meet the WSGI standard, too. This is not the best approach yet.
If you have this
if __name__ == "__main__": main()
You just need to add something like this to each script.
def myWSGIApp( environ, start_response ): with file( "temp", "w" ) as output: sys.stdout= output main() sys.stdout= __stdout__ status = '200 OK' headers = [('Content-type', 'text/plain')] start_response(status, headers) result= file( "temp", "r" ) return result
Then each script can be called as a WSGI application and can be connected to the basis of WSGI.
The best approach is to rewrite your scripts so that they do not use sys.stdout , but write to a file that is passed to them as an argument.
The test version of your server can be simple.
from wsgiref.simple_server import make_server httpd = make_server('', 8000, myWSGIApp)
When you have WSGI applications for your scripts, you can create a smarter WSGI Application that
See http://docs.python.org/library/wsgiref.html for information.
You can then configure Apache to use the WSGI server using mod_wsgi .
See http://code.google.com/p/modwsgi/ for more details.