Module Tour: Embedding Python with mod_python and mod_snake
by Rael Dornfest
11/08/2000
The Apache mod_python and mod_snake modules embed a Python interpreter right into Apache for speed, persistence, and advanced fun(ctionality).
Next stop on our module tour is a brief gander at a couple of modules that, as mod_perl does for Perl, drop the Python language into the Apache server for speedier applications, cross-request persistence, and the ability to speak directly to the server via the Apache API.
mod_python
Mod_python started its life as Httpdapy, written originally for the Netscape server, yet always intended to be cross-platform rather than server specific. From the README:
. . .I later learned that writing Httpdapy for every server is a task a little bigger and less interesting than I originally imagined. Instead, it seemed like providing a Python counterpart to the popular Perl Apache extension mod_perl that would give Python users the same (or better) capability would be a much more exciting thing to do. And so it was done.
Mod_python sports a longer history, (possibly) larger user-base, is simpler, and less "bleeding edge" than mod_snake, according to the mod_python FAQs. The mod_python site provides
some wonderful, easy-to-follow installation and configuration instructions, so I leave you in their capable hands.
mod_snake
Mod_snake is the newer of the two modules, being closer to mod_perl and its associated modules in functionality. Mod_snake supports the upcoming Apache 2.0 and allows you to embed Python in your HTML documents (you be the judge of whether or not that's a feature ;-)) and sports flexible configuration options.
Mod_snake's Website also provides detailed installation, configuration, testing, and programming documentation.
While it's hard to point to the differences between the two, mod_python seems to be more geared towards beginners and those not in need of all the bells and whistles of mod_snake. If, however, you're fiddling around with the Apache 2.0 alphas or want that extra flexibility and functionality, mod_snake is probably for you.
Resources
The following is a list of starting points from which to explore further some of the topics covered (or not) in this article.
- mod_python.org
- mod_python SourceForge Home - peruse the source code online
- mod_snake
- Python.org
- The Apache Server Project
- Apache 2.0
Rael Dornfest
is Chief Technology Officer at O'Reilly Media.
Read more HTTP Wrangler columns.
Discuss this article in the O'Reilly Network Apache Forum.
Return to the Apache DevCenter.