Python Apache Handler

Gerhard Häring gh at
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:

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

The documentation about this is a joke, though.

Remember that you can write custom Apache loggers quite easily with
"piped logs":

This looks roughly like this:

CustomLog "|/path/to/" common

## begin ##
import sys

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

-- Gerhard

More information about the Python-list mailing list