Python Apache Handler

Gerhard Häring gh at ghaering.de
Fri Jan 9 18:32:11 CET 2009


Scooter wrote:
> Does anyone have any good examples, or links thereto for using python
> as an Apache handler? And I should qualify all of this by saying I'm a
> python newbie, and while having experience with Apache, I've never
> done anything outside whats "in the box" .
> 
> What I'm looking for is how one might use Python not from the CGI/
> presentation side but more on the backend...i.e. for each page Apache
> serves up examine the request and update some headers, or add a cookie
> to the response. 

I vaguely remembered that mod_python can do such things. Looking again
it seems to be the case:
http://www.modpython.org/live/current/doc-html/pyapi-filter.html

> Or possibly use Python for writing a custom Apache
> logger. [...]

Maybe http://www.modpython.org/live/current/doc-html/dir-handlers-plh.html
The documentation about this is a joke, though.

Remember that you can write custom Apache loggers quite easily with
"piped logs": http://httpd.apache.org/docs/2.2/logs.html

This looks roughly like this:

CustomLog "|/path/to/my_script.py" common

## begin my_script.py ##
import sys

for line in sys.stdin:
    # do stuff
## end ##

-- Gerhard




More information about the Python-list mailing list