apache modules in python ?

Alan Kennedy alanmk at hotmail.com
Wed Apr 30 11:37:56 CEST 2003

Geirgat Jonas wrote:
> Is it possible to write modules for the apache http server in python ?

Just to be explicitly clear on what that means: You want to be able to
implement the Apache module API using python, and then dynamically load
the resulting module into Apache, and have it service requests?

Mod_python does indeed do exactly that: it implements the Apache module
API, in C, and permits the administrator to map URLs to python programs.
When it wants to execute a python program, mod_python has an embedded
python interpreter, through which it runs the programs, and serves the
resulting output back to the user.

If you were to write other Apache modules in python, say "mod_gzippy",
then you would need to also implement the Apache module API, in C. Code
for this is available in mod_python. 

Then you would want to call your python functionality which does
gzip'ping. Which means that your C code would need to call python code.
Due to the multithreaded nature of Apache, this can be a tricky
business. Python has a "Global Interpreter Lock", which allows only one
thread to be executing at a time. And it gets more complex when you are
using "foreign threads", i.e. Apache threads making function calls to
python threads. Again, mod_python implements all of this functionality. 

And does it correctly, having been thoroughly debugged over the years.

So, given the above considerations, is there a reason why you can't
simply use mod_python, which solves all of the hard problems for you?


alan kennedy
check http headers here: http://xhaus.com/headers
email alan:              http://xhaus.com/mailto/alan

More information about the Python-list mailing list