Differences between revisions 3 and 136 (spanning 133 versions)
Revision 3 as of 2006-08-15 09:30:47
Size: 6679
Editor: PaulBoddie
Comment: Reclassified stringtemplate, added string.Template.
Revision 136 as of 2015-01-10 14:39:00
Size: 15351
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
#pragma section-numbers off = Templating in Python =
<<TableOfContents(2)>>
Line 3: Line 4:
= Templating in Python =

Templating, and in particular Web templating, involves the presentation of information in a form which is often (but not always) intended to be readable, even attractive, to a human audience. Frequently, templating solutions involve a document (the template) which may look somewhat like the final output but perhaps in a simplified or stylized form, along with some data which must be presented using that template; combining these two things produces the final output which in Web templating is usually (but not always) a Web page of some kind.
Templating, and in particular web templating is a way to represent data in different forms. These forms often (but not always) intended to be readable, even attractive, to a human audience. Frequently, templating solutions involve a document (the template) and data. Template usually looks much like the final output, with placeholders instead of actual data (or example data in simplified form), bears common style and visual elements. Data which is presented using that template may be also separated in two parts - data required to be rendered, and data required for template itself (navigation elements if it is a site, button names if it is some UI). Combining template+data produces the final output which is usually (but not always) a web page of some kind.
Line 8: Line 7:
Line 11: Line 9:
The number of templating engines is so great because the mechanisms involved are pretty easy to write in Python, at least for a fairly basic template engine; [http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52305 this recipe from the Python Cookbook] shows how easy it is. The number of templating engines is so great because the mechanisms involved are pretty easy to write in Python, at least for a fairly basic template engine; [[http://code.activestate.com/recipes/52305/|this recipe from the Python Cookbook]] shows how easy it is.
Line 14: Line 12:
The simplest form of templating engine is that which merely substitutes values into a template in order to produce the final output. They sometimes provide tags for if statements or loops, but they are crude.
Line 15: Line 14:
The simplest form of templating engine is that which merely substitutes values into a template in order to produce the final output.

    * [http://docs.python.org/lib/node109.html string.Template] in the standard library
    * [http://www.stringtemplate.org stringtemplate] - employs recursion in order to provide support for complicated templating whilst avoiding side-effects
 * [[http://docs.python.org/2/library/string.html#template-strings|string.Template (python 2.x)]] & [[https://docs.python.org/3.4/library/string.html#template-strings|string.Template (python 3.x)]] in the python standard library.
 * [[http://www.stringtemplate.org/|stringtemplate]] - employs recursion in order to provide support for complicated templating whilst avoiding side-effects
 * [[http://mustache.github.com/|mustache]] - logic-less templates based on [[http://code.google.com/p/google-ctemplate/|CTemplate]] with implementation in many languages including Python
 * [[https://github.com/mll/ctemplate-python|ctemplate-python]] - fast templating with simple if/loop logic based on [[http://libctemplate.sourceforge.net|libCtemplate]]
Line 21: Line 20:
A popular approach with templating engines is to embed logic or control-flow statements into the templates themselves in a way that can make the the final output appear rather different from the original template. For example:
Line 22: Line 22:
A popular approach with templating engines is to embed logic or control-flow statements into the templates themselves in a way that can make the templates visually rather different from the final output, as well as introducing problems for some XML-based tools. Nevertheless, such templating engines may be more applicable to non-Web templating problems or for situations where separating logic from content may actually make the solution harder to understand. {{{
<table>
  <%
  
for item in items:
    %>
    <tr>
      <th>Name</th>
      <td><%= item.name %></td>
    </tr>
    <%
  %>
</table>
}}}
The introduction of such logic m
ay also cause problems for some XML-based tools. Despite these shortcomings, such templating engines may be more applicable to non-Web templating problems or for situations where separating logic from content may actually make the solution harder to understand.
Line 24: Line 37:
    * [http://airspeed.pythonconsulting.com/ Airspeed] - Velocity Templates for Python
    * ["Castalian"]
    * ["Cheetah"]
    * CubicTemp
    * [http://www.djangoproject.com/documentation/templates/ Django template system]
    * [[Anchor(Elements)]] [http://www.nthwave.net/elements/ Elements]
    * EmPy
    * [http://www.aerojockey.com/software/hrl HRL] Powerful macro preprocessor for HTML; macros can embed arbitrary Python code
    * [http://wsgiarea.pocoo.org/jinja/ Jinja]
    * [http://www.myghty.org/ Myghty] inspired by Perl's Mason
    * ["Spyce"]
    * [http://www.execulink.com/~robin1/wasp/readme.html WASP]
 * [[http://airspeed.pythonconsulting.com/|Airspeed]] - Velocity Templates for Python
 * [[Castalian]]
 * [[http://chameleon.readthedocs.org/en/latest/|Chameleon]] - fast page template implementation which compiles markup templates into python byte code. Used by Pyramid, Zope, Plone and Grok projects.
 * [[Cheetah]]
 * CubicTemp
 * [[https://docs.djangoproject.com/en/1.6/topics/templates/|Django template system]]
 * [[http://www.nthwave.net/elements/|Elements]]
 * EmPy
 * [[https://pypi.python.org/pypi/evoque|Evoque page on pypi]] - managed eval-based full-featured templating engine, for Python 2.4, 2.5, 2.6 '''and 3.0''', features such as unicode, dynamic overlays, ''format-extensible'' automatic quoting, in-process sandbox, et cetera, while still remaining small, simple and extremely fast -- performance benchmarks show it to be more or less as fast as Mako, and faster on simpler templates.
 * [[http://blog.aerojockey.com/post/hrl|HRL (HTML Redemption Language)]] - Powerful macro preprocessor for HTML; macros can embed arbitrary Python code. ( '''2010-07-04, Officially discontinued''')
 * [[http://genshi.edgewall.org/|Genshi]] - XML-based templating engine, used in the popular python tool [[trac]]. ''Performance tests show that it is the fastest of all xml based templating engines in Python.''
 * [[http://jinja.pocoo.org/|Jinja 2]] - an extensible, sandboxed text-based templating engine with Django-like syntax (but faster).
 * [[http://www.makotemplates.org/|Mako]] - a fast, non-xml, templating engine based on ideas from Myghty.
 * [[https://github.com/etianen/moody-templates|moody-templates]] - A fast, extensible templating engine for Python 3 with Django-like syntax.
 * [[http://www.myghty.org/|Myghty]] inspired by Perl's Mason, replaced by Mako and [[http://www.python.org/pypi/MyghtyUtils|MyghtyUtils]].
 * [[https://www.mems-exchange.org/software/DurusWorks/|Qpy]] provides a convenient mechanism for generating safely-quoted html text from python code. It does this by implementing a quoted-string data type and a modification of the python compiler.
 * [[http://quik.readthedocs.org/|Quik]] - A fast and lightweight Python template engine
 * [[http://codingrecipes.com/pml-a-python-template-engine|PML]] is a high performance template engine implemented in Python, it supports many advanced features such as template filters, output filters, and more.
 * [[http://www.simple-is-better.org/template/pyratemp.html|pyratemp]] - a very small (<500 LOC) but complete template-engine, using restricted python-expressions. There are also some [[http://www.simple-is-better.org/template/|benchmarks and comparisons]] of different template-engines.
 * [[Spyce]]
 * [[https://pypi.python.org/pypi/suit/|SUIT]] - powerful template engine that allows one to define their own syntax to transform templates by using rules.
 * [[http://pythonpaste.org/tempita|Tempita]] - a fairly simple, small templating language with full Python expressions
 * [[http://tt2.org/python/index.html|Template Toolkit]] - Python port of Perl template engine
 * [[http://davidbau.com/templet|Templet]] - a 90-line BSD-licensed utility that defines @stringfunction and @unicodefunction python function decorators for simple, robust, and speedy templating.
 * [[http://www.joonis.de/content/TemplitePythonTemplatingEngine|Templite+]] - A light-weight, fully functional, general purpose templating engine
 * [[http://www.kuwata-lab.com/tenjin/|Tenjin]] is a fast template engine implemented in pure Python. Some benchmarks have shown it to be about x2 faster than Mako, x3 than Cheetah, x9 than Django, x60 than Kid in some situations. However [[http://mindref.blogspot.com/2012/07/python-fastest-template.html|50% slower]] wheezy.template.
 * [[http://texthon.chipsforbrain.org|Texthon]] - Python-eval based template engine with a focus on generating readable code.
 * [[http://www.sourceforge.net/projects/the-next-please|thrases]] - format-free Python needing just needing a reserved string (default: ~~) for separating phrases. Template.init() analyses, which phrases are python and which not, building a python script for exec(). This script is containing only minimal overhead then - Template.render() is near to the theoretical maximum speed. Template.render() can also write directly on a file descriptor for improved performance.
 * [[https://bitbucket.org/akorn/wheezy.template|wheezy.template]] is written in pure Python code. It is a lightweight template library. The design goals achived:
  * Compact, Expressive, Clean: Minimizes the number of keystrokes required to build a template. Enables fast and well read coding.
  * Intuitive, No time to Learn: Basic Python programming skills plus HTML markup. You are productive just from start. Use full power of Python with minimal markup required to denote python statements.
  * Do Not Repeat Yourself: Master layout templates for inheritance; include and import directives for maximum reuse.
  * [[http://mindref.blogspot.com/2012/07/python-fastest-template.html|Blazingly Fast]]: Maximum rendering performance: ultimate speed and context preprocessor features.
Line 38: Line 72:
The following engines feature template documents whose sections are marked using special attributes (or, less frequently, special elements or tags). For example:
Line 39: Line 74:
The following engines feature template documents whose sections are marked using special attributes (or, less frequently, special elements or tags). In some systems, the sections are then manipulated within program code; in others, the template structure indicates sections which are to be repeated, omitted, and so on. Generally, the reason for annotating templates in this way (particularly through the use of attributes) is to better support the editing of such templates in XML-based tools which might otherwise complain about or damage template information if it were not included carefully in documents. {{{
<table annotation:element="items">
  <tr annotation:element="item">
    <th>Name</th>
    <td>{name}</td>
  </tr>
</table>
}}}
In some systems, the sections are then manipulated within program code; in others, the template structure indicates sections which are to be repeated, omitted, and so on, and the templating system then merges the template with some data structure provided by the program. Generally, the reason for annotating templates in this way (particularly through the use of attributes) is to better support the editing of such templates in XML-based tools which might otherwise complain about or damage template information if it were not included carefully in documents.
Line 41: Line 84:
    * [#ClearSilver] - uses special elements/tags
    * [http://freespace.virgin.net/hamish.sanderson/htmltemplate.html HTMLTemplate]
    * ["JonsPythonModules"] - uses special comment-like markers
    * [http://www.plope.com/software/meld3/ meld3] and [http://www.entrian.com/PyMeld PyMeld] are very similar
    * ["pso"]
    * [http://pytan.com/public/sprite/ Sprite] - uses special comment-like markers
    * ["teng"] - uses processing instruction-like markers
 * [[ClearSilver]] - uses special elements/tags
 * [[http://sourceforge.net/projects/py-templates//|HTMLTemplate]] - special attributes denote HTML elements that can be manipulated as Python objects ('''As of 2013-12-05, this project is no longer under active development.''')
 * JonsPythonModules - uses special comment-like markers
 * [[http://www.plope.com/software/meld3/|meld3]] and [[http://www.entrian.com/PyMeld|PyMeld]] are very similar
 * [[https://github.com/holtwick/pyxer|Pyxer]] - based on Genshi parser engine. Optimized for work with Google App Enginge (GAE)
 * [[pso]]
 * [[https://web.archive.org/web/20060819140627/http://pytan.com/public/sprite/|Sprite]] - uses special comment-like markers
 * [[teng]] - uses processing instruction-like markers
 * [[http://psilib.sf.net/webstring.html|webstring]] - uses attributes in XML/HTML templates and a specific character in text templates
 * [[https://pypi.python.org/pypi/XSLTools|XSLTools]] - uses special attributes (with XML documents providing the data)
 * [[http://gna.org/projects/pypa|PyPa]] - nested comment-delimited blocks that are accessible from Python code as objects.
 * [[http://opensource.perlig.de/tdi/|TDI]] - Manipulate tagged HTML/XML elements with normal Python code. Fast.
Line 49: Line 97:
In other systems, the annotations are actually evaluated in order to produce repeated sections to omit or to include sections, and so on: In other systems, the annotations are actually evaluated in order to produce repeated sections, to omit or include sections, and so on:
Line 51: Line 99:
    * [http://htmltmpl.sourceforge.net/ htmltmpl] - uses special elements/tags
    * [http://kid.lesscode.org/ Kid] - XML based, compiling template engine
    * [[Anchor(SimpleTAL)]][http://www.owlfish.com/software/simpleTAL/ SimpleTAL] - introduces a certain amount of logic but in an XML-compatible fashion
 * [[http://genshi.edgewall.org/|Genshi]] - Template engine inspired by Kid, supports both [[http://genshi.edgewall.org/wiki/Documentation/xml-templates.html|XML]] and [[http://genshi.edgewall.org/wiki/Documentation/text-templates.html|plain-text]] templates
 * [[http://sourceforge.net/p/kajiki/home/|kajiki]] - Template engine inspired by Genshi
 * [[http://htmltmpl.sourceforge.net/|htmltmpl]] - uses HTML-like elements/tags and supports compilation
 * [[https://pypi.python.org/pypi/kid/|Kid]] - XML based, compiling template engine
 * [[http://www.owlfish.com/software/simpleTAL/|SimpleTAL]] - introduces a certain amount of logic but in an XML-compatible fashion
 * [[http://sourceforge.net/projects/cherrypy/|CherryTemplate]] - is a Pythonic HTTP toolkit.
Line 56: Line 107:
The libraries in this section implement simpler markup languages that can be automatically converted to HTML. This lets you avoid having to write HTML by hand.
Line 57: Line 109:
The libraries in this section implement simpler markup languages
that can be automatically converted to HTML. This lets you avoid having to write HTML by hand.
 * [[http://www.methods.co.nz/asciidoc/|AsciiDoc]]
 * [[https://pypi.python.org/pypi/Markdown|Markdown]]
 * PyTextile
 * [[reStructuredText]]
 * [[http://txt2tags.sourceforge.net/|txt2tags]]
 * [[https://pypi.python.org/pypi/PottyMouth/2.2.1|PottyMouth]] (for untrusted text input)
 * [[http://code.google.com/p/python-creole/|Creole]] (creole to html and html to creole)
Line 60: Line 117:
    * [http://www.methods.co.nz/asciidoc/ AsciiDoc]
    * PyTextile
    * ReStructuredText
    * [http://txt2tags.sourceforge.net/ txt2tags]
== Template engines implemented as Internal DSL's ==
These engines are implemented as an internal DSL, that is, they don't process text into markup, rather they represent the final document as actual Python code and data structures. See: [[http://bitbucket.org/tavisrudd/throw-out-your-templates/src/tip/throw_out_your_templates.py|An overview of the benefits of this internal DSL approach vs external template languages]]

 * [[http://docs.g-vo.org/meetstan.html|Stan]]
 * [[http://breve.twisty-industries.com/|Brevé]]
 * [[http://dirty.googlecode.com/|Dirty]]
Line 66: Line 125:
'''Many of these links are dead. Perhaps someone more knowledgeable might want to fix or prune them.'''
Line 69: Line 129:
   * [http://starship.python.net/crew/friedrich/HTMLgen/html/main.html HTMLgen]
   * [http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/366000 HTMLTags ]
   * [http://dustman.net/andy/python/HyperText/ HyperText]
   * [http://markup.sourceforge.net/ markup ] A light-weight and flexible HTML/XML generator
   * [http://www.livinglogic.de/Python/xist/ XIST ]
   * [http://pyhtmloo.sourceforge.net/ pyhtmloo ] pyhtmloo is a library that allows python developers to use HTML code like any other python objects.
 * [[http://www.webelements.in/|WebElements]] allows creating html documents using python objects that represent their DOM equivalents, inspired by QT.
 * [[http://genshi.edgewall.org/|Genshi]] The genshi.builder module provides [[http://genshi.edgewall.org/wiki/Documentation/builder.html|simple markup generation]]
 * [[https://packages.debian.org/sid/python-htmlgen|HTMLgen]] A old-school module first written for Python 1.x. Debian's package maintainers' patches bring it into the twenty-first century with Python 2.7 compatibility. [[https://github.com/dbohdan/HTMLgen|Mirrored]] on GitHub.
 * [[https://web.archive.org/web/20080914004317/http://pylonshq.com/WebHelpers/module-webhelpers.htmlgen.html|webhelpers.htmlgen]] Kind of like HTMLGen, only much simpler. Like stan, only not.
 * [[https://pypi.python.org/pypi/html|html]] Provides a simple syntax to generate HTML, XHTML and XML.
 * [[http://code.activestate.com/recipes/366000/|HTMLTags]]
 * [[https://web.archive.org/web/20070202041542/http://dustman.net/andy/python/HyperText/|HyperText]]
 * [[http://markup.sourceforge.net/|markup]] A light-weight and flexible HTML/XML generator
 * [[http://www.livinglogic.de/Python/xist/|XIST]]
 * [[http://pyhtmloo.sourceforge.net/|pyhtmloo]] pyhtmloo is a library that allows python developers to use HTML code like any other python objects.
 * [[http://www.yattag.org/|Yattag]] Provides a readable way to write HTML or XML within Python using indented blocks instead of <tag>...</tag> constructs.
Line 77: Line 142:
Line 80: Line 144:
   * [http://www.ivy.fr/tahchee/ tahchee] - ["Cheetah"]-based static web site generator
   * [http://www.owlfish.com/software/PubTal/ PubTal] - [#SimpleTAL]-based static web site generator
   * [#Elements]
   * [http://www.voidspace.org.uk/python/rest2web/] - Generates Websites from ReST contents
See StaticSiteGenerator for the list.
Line 86: Line 147:
Line 89: Line 149:
   * [http://freemarker.org/index.html FreeMarker] (with Jython data binding)
   * [http://java.sun.com/products/jsp Java Server Pages, JSP]
   * [http://jakarta.apache.org/velocity/index.html Velocity]
   * [http://www.webmacro.org/ WebMacro]
 * [[http://freemarker.org/index.html|FreeMarker]] (with Jython data binding)
 * [[http://www.oracle.com/technetwork/java/jsp-138432.html|Java Server Pages, JSP]]
 * [[http://velocity.apache.org/|Velocity]]
 * [[http://www.webmacro.org/|WebMacro]]
Line 95: Line 155:

   * [[Anchor(ClearSilver)]] ClearSilver (HTML generation)
 * ClearSilver - HTML generation, uses HDF as input format
----
CategoryTemplate

Templating in Python

Templating, and in particular web templating is a way to represent data in different forms. These forms often (but not always) intended to be readable, even attractive, to a human audience. Frequently, templating solutions involve a document (the template) and data. Template usually looks much like the final output, with placeholders instead of actual data (or example data in simplified form), bears common style and visual elements. Data which is presented using that template may be also separated in two parts - data required to be rendered, and data required for template itself (navigation elements if it is a site, button names if it is some UI). Combining template+data produces the final output which is usually (but not always) a web page of some kind.

Templating Engines

There are many, many different HTML/XML templating packages and modules for Python that provide different feature sets and syntaxes. These libraries usually assume that you know how to write HTML or XML.

The number of templating engines is so great because the mechanisms involved are pretty easy to write in Python, at least for a fairly basic template engine; this recipe from the Python Cookbook shows how easy it is.

Engines using Value Substitution

The simplest form of templating engine is that which merely substitutes values into a template in order to produce the final output. They sometimes provide tags for if statements or loops, but they are crude.

Engines Mixing Logic into Templates

A popular approach with templating engines is to embed logic or control-flow statements into the templates themselves in a way that can make the the final output appear rather different from the original template. For example:

<table>
  <%
  for item in items:
    %>
    <tr>
      <th>Name</th>
      <td><%= item.name %></td>
    </tr>
    <%
  %>
</table>

The introduction of such logic may also cause problems for some XML-based tools. Despite these shortcomings, such templating engines may be more applicable to non-Web templating problems or for situations where separating logic from content may actually make the solution harder to understand.

  • Airspeed - Velocity Templates for Python

  • Castalian

  • Chameleon - fast page template implementation which compiles markup templates into python byte code. Used by Pyramid, Zope, Plone and Grok projects.

  • Cheetah

  • CubicTemp

  • Django template system

  • Elements

  • EmPy

  • Evoque page on pypi - managed eval-based full-featured templating engine, for Python 2.4, 2.5, 2.6 and 3.0, features such as unicode, dynamic overlays, format-extensible automatic quoting, in-process sandbox, et cetera, while still remaining small, simple and extremely fast -- performance benchmarks show it to be more or less as fast as Mako, and faster on simpler templates.

  • HRL (HTML Redemption Language) - Powerful macro preprocessor for HTML; macros can embed arbitrary Python code. ( 2010-07-04, Officially discontinued)

  • Genshi - XML-based templating engine, used in the popular python tool trac. Performance tests show that it is the fastest of all xml based templating engines in Python.

  • Jinja 2 - an extensible, sandboxed text-based templating engine with Django-like syntax (but faster).

  • Mako - a fast, non-xml, templating engine based on ideas from Myghty.

  • moody-templates - A fast, extensible templating engine for Python 3 with Django-like syntax.

  • Myghty inspired by Perl's Mason, replaced by Mako and MyghtyUtils.

  • Qpy provides a convenient mechanism for generating safely-quoted html text from python code. It does this by implementing a quoted-string data type and a modification of the python compiler.

  • Quik - A fast and lightweight Python template engine

  • PML is a high performance template engine implemented in Python, it supports many advanced features such as template filters, output filters, and more.

  • pyratemp - a very small (<500 LOC) but complete template-engine, using restricted python-expressions. There are also some benchmarks and comparisons of different template-engines.

  • Spyce

  • SUIT - powerful template engine that allows one to define their own syntax to transform templates by using rules.

  • Tempita - a fairly simple, small templating language with full Python expressions

  • Template Toolkit - Python port of Perl template engine

  • Templet - a 90-line BSD-licensed utility that defines @stringfunction and @unicodefunction python function decorators for simple, robust, and speedy templating.

  • Templite+ - A light-weight, fully functional, general purpose templating engine

  • Tenjin is a fast template engine implemented in pure Python. Some benchmarks have shown it to be about x2 faster than Mako, x3 than Cheetah, x9 than Django, x60 than Kid in some situations. However 50% slower wheezy.template.

  • Texthon - Python-eval based template engine with a focus on generating readable code.

  • thrases - format-free Python needing just needing a reserved string (default: ~~) for separating phrases. Template.init() analyses, which phrases are python and which not, building a python script for exec(). This script is containing only minimal overhead then - Template.render() is near to the theoretical maximum speed. Template.render() can also write directly on a file descriptor for improved performance.

  • wheezy.template is written in pure Python code. It is a lightweight template library. The design goals achived:

    • Compact, Expressive, Clean: Minimizes the number of keystrokes required to build a template. Enables fast and well read coding.
    • Intuitive, No time to Learn: Basic Python programming skills plus HTML markup. You are productive just from start. Use full power of Python with minimal markup required to denote python statements.
    • Do Not Repeat Yourself: Master layout templates for inheritance; include and import directives for maximum reuse.
    • Blazingly Fast: Maximum rendering performance: ultimate speed and context preprocessor features.

Engines with Annotated Templates

The following engines feature template documents whose sections are marked using special attributes (or, less frequently, special elements or tags). For example:

<table annotation:element="items">
  <tr annotation:element="item">
    <th>Name</th>
    <td>{name}</td>
  </tr>
</table>

In some systems, the sections are then manipulated within program code; in others, the template structure indicates sections which are to be repeated, omitted, and so on, and the templating system then merges the template with some data structure provided by the program. Generally, the reason for annotating templates in this way (particularly through the use of attributes) is to better support the editing of such templates in XML-based tools which might otherwise complain about or damage template information if it were not included carefully in documents.

  • ClearSilver - uses special elements/tags

  • HTMLTemplate - special attributes denote HTML elements that can be manipulated as Python objects (As of 2013-12-05, this project is no longer under active development.)

  • JonsPythonModules - uses special comment-like markers

  • meld3 and PyMeld are very similar

  • Pyxer - based on Genshi parser engine. Optimized for work with Google App Enginge (GAE)

  • pso

  • Sprite - uses special comment-like markers

  • teng - uses processing instruction-like markers

  • webstring - uses attributes in XML/HTML templates and a specific character in text templates

  • XSLTools - uses special attributes (with XML documents providing the data)

  • PyPa - nested comment-delimited blocks that are accessible from Python code as objects.

  • TDI - Manipulate tagged HTML/XML elements with normal Python code. Fast.

In other systems, the annotations are actually evaluated in order to produce repeated sections, to omit or include sections, and so on:

  • Genshi - Template engine inspired by Kid, supports both XML and plain-text templates

  • kajiki - Template engine inspired by Genshi

  • htmltmpl - uses HTML-like elements/tags and supports compilation

  • Kid - XML based, compiling template engine

  • SimpleTAL - introduces a certain amount of logic but in an XML-compatible fashion

  • CherryTemplate - is a Pythonic HTTP toolkit.

HTML Shorthand Processors

The libraries in this section implement simpler markup languages that can be automatically converted to HTML. This lets you avoid having to write HTML by hand.

Template engines implemented as Internal DSL's

These engines are implemented as an internal DSL, that is, they don't process text into markup, rather they represent the final document as actual Python code and data structures. See: An overview of the benefits of this internal DSL approach vs external template languages

HTML Generation Packages

Many of these links are dead. Perhaps someone more knowledgeable might want to fix or prune them.

These packages are not really templating systems in that they do not typically employ a template document as such to define the form of the output they produce, but they can be useful in applications where it is more convenient to programmatically generate output.

  • WebElements allows creating html documents using python objects that represent their DOM equivalents, inspired by QT.

  • Genshi The genshi.builder module provides simple markup generation

  • HTMLgen A old-school module first written for Python 1.x. Debian's package maintainers' patches bring it into the twenty-first century with Python 2.7 compatibility. Mirrored on GitHub.

  • webhelpers.htmlgen Kind of like HTMLGen, only much simpler. Like stan, only not.

  • html Provides a simple syntax to generate HTML, XHTML and XML.

  • HTMLTags

  • HyperText

  • markup A light-weight and flexible HTML/XML generator

  • XIST

  • pyhtmloo pyhtmloo is a library that allows python developers to use HTML code like any other python objects.

  • Yattag Provides a readable way to write HTML or XML within Python using indented blocks instead of <tag>...</tag> constructs.

Static Website Generators

Static website generators are more than templating engines in that they create the whole site structure, not just individual files. While templating is an important part of their function, determining the site structure and incorporating structural information in the output (for example to automatically generate navigational elements) is what really makes a static website generator a useful tool.

See StaticSiteGenerator for the list.

Java Templating Engines

The following templating engines are accessible or usable via Jython:

CPython-accessible C Templating Engines

  • ClearSilver - HTML generation, uses HDF as input format


CategoryTemplate

Templating (last edited 2019-12-15 07:18:08 by FrancesHocutt)

Unable to edit the page? See the FrontPage for instructions.