Module Tour: Embedding Python with mod_python and mod_snake

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 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 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.

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.

Rael Dornfest
is Founder and CEO of Portland, Oregon-based Values of n. Rael leads the Values of n charge with passion, unearthly creativity, and a repertoire of puns and jokes  some of which are actually good.
Prior to founding Values of n, he was O'Reilly's Chief Technical Officer, program chair for the O'Reilly Emerging Technology Conference (which he continues to chair), series editor of the bestselling Hacks book series, and instigator of O'Reilly's Rough Cuts early access program. He built Meerkat, the first web-based feed aggregator, was champion and co-author of the RSS 1.0 specification, and has written and contributed to six O'Reilly books.
Rael's programmatic pride and joy is the nimble, open source blogging application Blosxom, the principles of which you'll find in the Values of n philosophy and embodied in Stikkit: Little yellow notes that think.