Ibis

A template engine for people who enjoy the simpler things in life.

Version 3.3.0

Quickstart Tutorial


A template starts life as a simple string containing template markup. The Template class takes this string as input and compiles it into a template object:

>>> import ibis
>>> template = ibis.Template('{{foo}} and {{bar}}')

Compilation only needs to happen once; the template can then be rendered multiple times by calling its .render() method with a dictionary of key-value pairs:

>>> template.render({'foo': 'ham', 'bar': 'eggs'})
'ham and eggs'

>>> template.render({'foo': 1, 'bar': 2})
'1 and 2'

In practice you'll most likely store your templates in the form of text files. You can handle the process of loading these files, compiling them into templates, and storing the resulting Template objects yourself, or you can take advantage of the built-in FileLoader class to take care of the details for you.

A FileLoader instance is initialized with a path to a base template directory:

loader = ibis.loaders.FileLoader('/path/to/base/dir')

Calling the loader with a template name (a string interpreted as a path to a text file stored in the base directory) will return the corresponding template object:

template = loader('template.txt')

The loader compiles the templates once and caches them in memory for future lookups. You can learn more about using template loaders here.