The Little Python That Could


I've been pursuing my old NewWikiMigration project, and it's pretty much settled that I'll be aiming at replacing this site's Apache/PHP combo with an all-Python, filesystem-oriented approach. The reasons are manifold, but I can summarize them here again as follows:

  • I need a smaller, tighter codebase (PhpWiki is huge, and the drastic re-plumbing I've been doing over the past couple of years hasn't helped). Something I can build upon.
  • I want something that runs fast while using the smallest possible amount of system resources.
  • I want something with a built-in web server for:
    • Portability (Python runs everywhere, and much better than Java).
    • Security reasons (scripting language based servers are harder to attack and easier to instrument against attacks).
    • Tweaking every single aspect of the HTTP connection (from caching to compression, as well as request throttling, IP banning, etc.)
  • I want something that I can simply copy across to another machine - no databases, no special requirements, just Python (and Subversion for Wiki versioning). Zero deployment time.

So I started looking around for suitable bits of code to kick-start my new setup. In my usual strife for completeness, here's what I churned through, in more or less chronological order:

Zope

Like, you've got to be kidding, right? It's monstruous, and the only bits I would use from it are related to medusa and ZServer. Still, I gave it some thought:

Pluses:

  • Near-fanatical following.
  • Does it all, from Wikis to photo albums.
  • Truckloads of documentation.

Minuses:

  • Near-fanatical following.
  • Too big, complex, fiddly to use and customize.
  • Large codebase, steep learning curve.

Next contestant, please.

Twisted

Sheer power. I've come across it many times before, and would not hesitate to base real-life applications on it. nevertheless, it is a bit too much for what I intend.

Pluses:

  • Stable, mature solution.
  • Web server does HTTP 1.1, chunked transfers, SSL.
  • Reasonably well-documented, active developer community.

Minuses:

  • Large codebase, steep learning curve.
  • Moving target (portions in flux).
  • A bit too demanding in terms of footprint.

So I went back to basics, and started looking at smaller stuff.

medusa

Extremely lean and mean server framework, with a very neat conceptual approach. I keep coming back, but after spending a couple of hours trying to add gzip compression, I've found it less than intuitive to extend, and couldn't yet figure out how to manipulate request headers.

Pluses:

  • Fast. Real fast, probably the best Python web server ever.
  • Supports HTTP 1.1, chunked transfers.
  • Good conceptual design.

Minuses:

  • A bit too low-level.
  • Codebase is pretty much dead in the water.
  • No working gzip support.

Moving up the ladder, I started looking at slightly more complex stuff with templating support.

Karrigell

This was the first "light" application server I looked at, and it kind of set the tone for the rest of my search. It was simple, neat and effective, although in need of a bit more polish.

Pluses:

  • Templating, session, authentication, internationalization support.
  • Enough of a mix between object orientation and templating for real-life work.
  • Small code base.

Minuses

  • Simplistic web server based on BaseHTTPServer. No gzip support, no HTTP 1.1 features, etc.
  • Small developer community (almost no activity on mailing-lists).
  • Documentation needs some work.

CherryPy

With this one, I felt I was getting closer. It was slick, relatively easy to get into, and had a small active developer community, but somehow I couldn't get to grips with the coding philosophy.

Pluses:

  • Fast, multi-threaded web server.
  • Small, readable codebase.
  • Active developer community.

Minuses:

  • HTTP server not quite all there yet (although I've seen patches for HTTP 1.1, SSL and gzip support).
  • Not enough samples for me to quickly get to grips with a couple of concepts.
  • A bit too much assembly required.

Snakelets

This one was the little hidden jewel. Besides a very neat, servlet-like approach, it has a central administration console that lets you restart/reload running applications, as well as a small, manageable codebase. It requires quite a bit of work on the HTTP optimization front, but hey, that's one of the things I've always wanted to do.

Pluses:

  • Very slick web administration, drop-in registration of modules, on-the-fly updating, etc.
  • Nice, small, neat, almost Zen-like codebase with adequate documentation.
  • Seems to be completely UTF-8-clean (or transparent).

Minuses:

  • No HTTP 1.1 support, no gzip encoding, etc.
  • Tricky to debug some snakelet issues (might be just me).
  • Ony one developer (bug-fixing will take time).

Conclusion

So, until I find something better, I'm going to have a go at Snakelets. If you happen to find something along these lines (simple and with a good HTTP implementation), feel free to drop me a line.


See Also:

PHP