Chevron Mustache Templating

0.14.0 · active · verified Thu Apr 09

Chevron is a lightweight, pure-Python implementation of the Mustache templating language. It provides a simple API for rendering templates using dictionaries or objects as data contexts. It adheres closely to the Mustache specification. The current version is 0.14.0, and it generally follows an as-needed release cadence for bug fixes and minor improvements, with long periods of stability.

Warnings

Install

Imports

Quickstart

Render a Mustache template string with provided data. Chevron handles basic variables, sections, and lists according to the Mustache specification.

import chevron

template_string = 'Hello, {{name}}! You are {{age}} years old.'
data_context = {'name': 'World', 'age': 42}

rendered_output = chevron.render(template=template_string, data=data_context)
print(rendered_output)

# Example with a list and conditional section
template_list = 'Users:\n{{#users}}- {{name}} (ID: {{id}})\n{{/users}}'
data_list = {'users': [{'name': 'Alice', 'id': 1}, {'name': 'Bob', 'id': 2}] }
rendered_list = chevron.render(template=template_list, data=data_list)
print(rendered_list)

view raw JSON →