Project Melody: Template languages
This post is about a project of mine called Melody. It stores pieces of information and helps with visualizing and manipulating that information, so you could call it a PIM (Personal Information Manager) – but I think that name has been used and abused too much already. Let's say it's a tool for flexible, fine-grained information wrangling. I'll describe it properly in another post; for now, I want to talk about template languages.
See, I want to use web page stuff (HTML, CSS, JavaScript) as a simple user interface toolkit for Melody. The advantages are obvious: it's a well-understood, highly evolved way of presenting information; tools are readily available; and there's excellent cross-platform support (read: browsers). I'm building Melody in Python, so I need a Python template language to generate those HTML pages.
My first choice was Django's template system. It's a simple, all-in-one solution that I already know and it comes with a built-in HTTP server for development. But Django's template system is dumbed-down for non-programmers: you can't write Python code in a template and you can't access attributes whose names start with an underscore. You have to prepare the data before rendering the template, or use template tags. I want something quick-and-dirty that allows me to experiment easily without writing code in two or three separate places, and the Django template system is not a good fit.
So I started looking around. Python is supposed to have many template language projects, so there has to be one that does mostly what I need. At Eau de Web we work a lot with Zope, so I've learned TAL. It's old and ugly and kludgy but it's based on a really nice idea: template logic is written as attributes of XML tags. Since you're generating HTML or XHTML (not arbitrary text strings), this makes a lot of sense. Turns out, other people liked the idea too, and they built newer, better systems than TAL.
Next in line was Kid. Its syntax is nice and light but, for some reason, you can only pass data to a template when you create it, so you can't share template instances because passing data to a template alters the template object. Kid also has this weird thing where it compiles templates to python code, which you can import as a module. Too much global stuff for my taste. So I looked around some more and found Genshi which, according to their FAQ, builds on Kid's experience. For now I've settled on Genshi, it seems to be just what I need. The XML-oriented approach might prove useful if I want to mix data from several objects into a single view.
There's an interesting lesson here. When I started building code for my blog, about one year ago, I knew there were many Python web frameworks to choose from. I picked Django because it felt "safe": the project site was beautiful, it had good documentation, and I had heard good things about Django from several people. I didn't have time (and was too lazy) to look carefully at alternatives. That's what first attracts people when they're choosing a tool: the feeling of safety. Today I needed a tool for a specific job, so I looked more closely at the technical merits of each option. Feeling safe is still important though: the fact that Genshi is built by the Edgewall people (who are also behind the excellent Trac project) gave me confidence to try it out.

Reader Comments
First post!
Take a look at jinja2 from pocoo. Its similar to Django's templating system, but allows method calls which imho makes it much more usable and requires less proxying via specialized tags. Its faster too.