Skip to content
Simple Template Engine for Python
Find file
New pull request
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

step - Simple Template Engine for Python

step is a pure-Python module providing a very simple template engine with minimum syntax. It supports variable expansion, flow control and embedding of Python code.


Use pip:

# pip install step-template

or download the package from GitHub and run the install script:

# python install

Basic usage

A template is a string containing any kind of textual content and a set of directives representing variables, control structures and blocks of Python code.

Variables are enclosed in {{}} and follow the same syntax rules as Python variables; e.g.:

This is variable x: {{x}}
This is the third item of my_list: {{my_list[2]}}
This is not a variable: \{\{x\}\}

Flow control expressions are written like regular Python control structures, preceded by the % sign and must be closed by a %end<statement> tag; e.g.:

%if (x > 2):
    x is greater than 2
    x is {{x}}

All text between <% and %> is considered Python code; you can use the builtin echo() function to output some text from within Python code blocks; e.g.:

import time
echo("Current timestamp is {}".format(time.time()))
<\% This is not Python code %\>

You can use the special function isdef() to perform some actions only if a name is defined in the template namespace; e.g.:

%if isdef("my_var")
    my_var is {{my_var}}

The setopt() function allows you to enable options that modify the template output; the only supported option is 'strip', which removes leading/trailing whitespace, contiguous whitespace and empty lines and defaults to true; e.g.:

<%setopt("strip", True)%>

The 'strip' option can also be given as a parameter during Template object creation; e.g.:

tmpl = step.Template(TEMPLATE_STRING, strip=True)

A backslash at the end of a line will suppress the newline character.


More examples and a detailed description of the module and its classes are available at


To run the test suite, just run python test.


Copyright (c) 2012 Daniele Mazzocchio ( Several improvements by Erki Suurjaak.

Licensed under the BSD license (see file).

Something went wrong with that request. Please try again.