Genshi (templating language)

From Wikipedia, the free encyclopedia
  (Redirected from Genshi (Templating Language))
Jump to navigation Jump to search
Developer(s)Edgewall Software
Initial releaseAugust 3, 2006; 12 years ago (2006-08-03)
Stable release
0.7 / January 27, 2013; 6 years ago (2013-01-27)
Repository Edit this at Wikidata
Operating systemCross-platform
TypeTemplate Engine

Genshi is a template engine for XML-based vocabularies written in Python. Genshi is used to easily insert generated output into XML-based languages, usually HTML, and reuse elements between documents. Genshi's syntax is based on Kid, but its architecture is different. Genshi aims to implement some of its functionality while processing templates faster, by dynamically processing templates using a stream based API, instead of compiling templates to Python code.[1]

Genshi can be used with several Python web frameworks, such as CherryPy,[2][3] TurboGears,[4] Pylons[5] and web2py.[6] Genshi has replaced Kid in the TurboGears 2.x web framework.[7]

Genshi markup[edit]

Genshi makes use of namespaces to embed instructions into HTML. A typical instruction is given as an attribute, with a Python expression inside the quotes. For example, the following will render a paragraph that shows 4:

<html xmlns="" xmlns:py="">
        <p py:content="2 + 2">This will be replaced with 4</p>

Because of the use of namespaces, Genshi can be used in WYSIWYG HTML editors.[8][9]

Differences between Kid and Genshi[edit]

  • Genshi directly interprets templates (unlike Kid, which generates Python code)[10]
  • Genshi uses XInclude for template reuse[10]
  • Genshi adds attributes Kid does not have, like py:choose[10]
  • Genshi templates are easier to debug, because it tracks template source file names and line numbers, and errors from Genshi's interpreter produce more comprehensible stack traces than from Kid's generated code. [10]


  1. ^ "What is Genshi?". Retrieved 2008-01-20.
  2. ^ "CherryPy – Genshi". Retrieved 2009-09-26.
  3. ^ "Genshi - CherryPy Tools - Trac". Archived from the original on 2012-07-04. Retrieved 2009-09-26.
  4. ^ "Genshi Templating". Retrieved 2008-01-20.
  5. ^ "Genshi Templates - Pylons Cookbook". Retrieved 2008-01-20.
  6. ^ "web2py: Enterprise Web Framework". Retrieved 2009-09-26.
  7. ^ Ramm, Mark. "TurboGears 1.1 and Beyond". Retrieved 2008-01-20.
  8. ^ "Choosing a templating language". Archived from the original on 2010-06-16. Retrieved 2010-05-30.
  9. ^ "Choosing a templating language". Archived from the original on 2008-01-17. Retrieved 2008-01-20.
  10. ^ a b c d "Comparing Genshi to Kid". Retrieved 2008-01-20.

External links[edit]