[CentralOH] Python vs. Apache

William McVey wam at cisco.com
Wed Aug 6 17:49:03 CEST 2008

On Tue, 2008-08-05 at 22:51 -0400, Mark Erbaugh wrote:
> I want to do some server side programming in Python for my Apache
> server.  From what I've seen there are a bunch of different ways to do
> it.
> mod_python
> mod_wsgi / fastcgi or fcgi / wsgiref
> wsgiref

Don't forget the option of building on top of BaseHTTPServer (or
SimpleHTTPServer) as well as the option of using the twisted web server.
All this can be seamlessly integrated into an Apache based website with
a mod-rewrite rule that reverse proxies requests to the python-based
service running on another port.

> Is there a 'preferred' method?  

Yes, there are many preferred methods. The problem is that set of
preferred methods vary depending on the developer you ask and even in
some cases the project that developer is working on.

> Is there a document that compares
> various approaches?

It's not really comparing, but it's worth reviewing:
http://wiki.python.org/moin/WebProgramming and

> I understand the limitations of pure CGI as Python has to be started for
> every request.

Not quite always the case. If your CGI scripts are written in python,
you can use mod_python.cgihandler to execute those scripts without
forking additional copies of python (with some caveats related to thread
management). I'm certainly not advocating this approach, but it is
important to know where the true limits are.

> At this point, I'm looking to do the programming in Python so I'm not
> considering a Python-based web framework.

Programming an application using a full stack web framework such as
Django or TurboGears *is* programming in python, so implying that you
are not considering these frameworks because you want to program in
python doesn't make sense to me. If anything, web apps coded using these
frameworks generally have a higher percentage of python code than other
approaches since you generally don't have to have embedded SQL or HTML
in your application. 

More importantly though is that a "framework" is just a set of generally
useful functionality that has been provided to you so that you don't
have to implement that functionality in your own code. Packages like
mod_wsgi, wsgiref, mod_python and even cgi.py are all web development
frameworks. They may not be full-stack frameworks that provide all the
functionality of something like Django or Turbogears, but they're
providing the application writer an easier to use or more powerful
interface for building their app than if that framework didn't exist.
It's also important to realize that even with the full stack frameworks,
most of the provided functionality is optional. For example, if you
don't need middleware, you don't need to enable it. If you don't want
object to relational database mapping, you don't have to use it.

  -- William

More information about the CentralOH mailing list