evoque - managed eval-based freeform templating
Evoque is a full-featured and generic text templating system for python using a simple $-substitution syntax and providing support for flow control, nested templates, overlays, inter-template addressing and invocation, cache management, arbitrary python expressions, advanced python % operator string formatting, restricted execution, automatic cross-site scripting protection, advanced encoding guessing algorithm, and more.
Allowing only python expressions and a managed evaluation namespace, Evoque offers a surprising level of simplicity, versatility and performance.
Buzz
- Full-featured pure python templating engine / 957 SLOC
- Automatic input quoting / XSS protection
- Restricted execution
- Every text file is a template
- Unicode
- Simplicity
- Speed
Snapshot
Usage from within an application
Templates are always part of a Collection in a Domain, i.e. the Domain and default Collection instances are always created, be it explicitly or implicitly. The preferred way to load/retrieve a Template is via a Domain instance (if necessary this implicitly creates a default Collection instance):
It may sometimes be more convenient to instantiate directly (if necessary this implicitly creates both Domain and default Collection instances):
Basic benchmark
A small template, doing a variety of standard templating tasks such as looping, calling sub-templates, escaping of data, etc. Time is averaged over 2000 renderings.
| Engine | Time | Quoting | Version | Remark |
|---|---|---|---|---|
| qpy | 0.86 ms | automatic | 1.6 | automatic safe quoting, h8 |
| evoque | 2.50 ms | automatic | ||
| evoque_mq | 2.26 ms | manual | manual quoting, no qpy | |
| evoque_r | 3.09 ms | automatic | restricted execution | |
| mako | 2.73 ms | manual | 0.1.10 | |
| genshi_text | 6.54 ms | manual | 0.4.4 | |
| genshi | 15.03 ms | automatic | 0.4.4 | xml mode |
Del.icio.us