Genshi Compiler 0.1.1

Genshi template compiler

  Add it to your Download Basket!

 Add it to your Watch List!


Rate it!
send us
an update
MIT/X Consortium License 
Viktor Ferenczi
ROOT \ Programming \ Compilers
Genshi Compiler is a tool that allows for compiling simple Genshi XML templates to pure Python code.

How to install:

- Download and install the source distribution or installer appropriate for you OS
- Execute easy_install genshi_compiler

Genshi Compiler allows for rendering your Genshi template to Python source code. You can save the code as a Python module or compile it into a directly usable module object in memory. Just call the render function on the module with your template parameters to render the whole template or any of your template functions to render those fragments separately.

According to my initial benchmarks the rendering speed is typically ~40x faster than doing the same using Genshi. There is a cost of this speedup, certainly. Some of Genshi's dynamic features are not available, most notably anything that depends on a template loader (xi:include), the XML element tree representation (py:match) or the token stream (filters).

Includes can be replaced by importing and calling other compiled template modules directly, so that is not a real limitation. Generic macro support (py:match) seems to be hopeless without slowing down the generated code considerably and loosing most of the performance gain. Token streams might be supported in the future.

This solution still allows you to speed up the most time critical parts (rendering large tables, trees, or lots of HTML user interface elements) considerably without too much effort, providing you can afford loosing the above functionality. It is also possible to combine Genshi and compiled template code for maximum flexibility and performance.

Python 3 support is planned.

Last updated on July 19th, 2011


#Genshi template #template compiler #Genshi compiler #Genshi #template #compiler #codegeneration

Add your review!