Pystache

0.6.8 · active · verified Thu Apr 09

Pystache is a Python implementation of the Mustache templating language, emphasizing a logic-free approach to separate presentation from application logic. It fully supports the Mustache spec and is currently maintained as a community fork. The latest stable release is 0.6.8, released on March 18, 2025.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the basic usage of Pystache with direct rendering, using the Renderer class for more control, and integrating with a simple Python object as a 'view' for data.

import pystache

# Simplest rendering
template = "Hello, {{person}}!"
context = {"person": "World"}
print(pystache.render(template, context))

# Using Renderer for more control (e.g., custom template directories)
renderer = pystache.Renderer()
print(renderer.render(template, context))

# Using a dedicated view class (no inheritance needed since 0.5.0)
class SayHello:
    def to(self):
        return "Pizza"

hello_view = SayHello()
template_view = "Hello, {{to}}!"
print(renderer.render(template_view, hello_view))

view raw JSON →