skip to navigation
skip to content

Not Logged In

tonnikala 0.14

Python templating engine - the one ton solution

Latest Version: 0.15


Tonnikala is the latest reincarnation among the Python templating languages that feed on Kid-inspired XML syntax. It rejects the Kid and Genshi notions of tagstreams and trees, and follows in footsteps of Chameleon and Kajiki in making the template to compile into Python bytecode directly. The syntax is very close to that of Kajiki, but the internals are very different: Tonnikala writes code as Abstract Syntax Trees and optimizes the resulting trees extensively. In addition, there is an optional speed-up module (currently Python 3 only), that provides a specialized class used for output buffering.


from tonnikala.loader import Loader

template_source = u"""
    <tr py:for="row in table">
        <py:for each="key, value in row.items()"

template = Loader().load_string(template_source)

ctx = {
    'table': [dict(a=1,b=2,c=3,d=4,e=5,f=6,g=7,h=8,i=9,j=10)
        for x in range(1000)]


Template inheritance

<title><py:block name="title_block">I am ${title}</py:block></title>

<py:extends href="">
<py:block name="title_block">But I am ${title} instead</py:block>


To load templates from files, use the tonnikala.FileLoader class:

loader = FileLoader(paths=['/path/to/templates'])
template = loader.load('')

A FileLoader currently implicitly caches all loaded templates in memory.


To render the template:

result = template.render(ctx)

You can specify a block, or no-argument def to render explicitly:

result = template.render(ctx, funcname='title_block')


Alpha, working features are

  • Structural elements py:if, py:unless, py:def, py:for, py:replace, py:content
  • Basic template inheritance: py:extends and py:block; the child template also inherits top level function declarations from the parent template, and the child can override global functions that the parent defines and uses.
  • Expression interpolation using $simple_identifier and ${complex + python + "expression"}
  • Boolean attributes: <tag attr="${False}">, <tag attr="$True">
  • Implicit escaping
  • Disabling implicit escaping (literal())
  • Python 3 speedups

Upcoming features:

  • Structural elements: py:vars, py:switch, py:case; py:else for for, if and switch.
  • Python 2 speedups
  • Custom tags mapping to py:def
  • I18N with optional in-parse-tree localization
  • Javascript as the target language
  • Pluggable frontend syntax engines
  • Pluggable expression languages akin to Chameleon
  • Even better template inheritance
  • Importing def blocks from another template: py:import
  • Documentation
  • Pyramid integration


Antti Haapala

File Type Py Version Uploaded on Size
tonnikala-0.14.tar.gz (md5) Source 2013-12-08 4KB
  • Downloads (All Versions):
  • 0 downloads in the last day
  • 55 downloads in the last week
  • 277 downloads in the last month