Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 0.1.10 instead.
Reason given by maintainers: 0.1.9 only published the macOS Intel wheel. Linux and Apple Silicon have no installable file. Use 0.1.8.

dotpromptz-handlebars

PyPI Python License Downloads

CI codecov OpenSSF Scorecard

GitHub stars OSS Insight

Star History Chart

A high-performance Handlebars template engine for Python, powered by Rust.

This package provides Python bindings to handlebars-rust, offering near-native performance for template rendering while maintaining a Pythonic API.

Features

  • Fast: Rust-powered template compilation and rendering
  • Compatible: Implements the Handlebars specification
  • Safe: HTML escaping by default, with options for raw output
  • Extensible: Support for custom helpers and partials
  • Type-safe: Full type hints for IDE support

Installation

pip install dotpromptz-handlebars

Quick Start

from handlebarrz import Template

# Create a template instance
template = Template()

# Register and render a template
template.register_template('greeting', 'Hello, {{name}}!')
result = template.render('greeting', {'name': 'World'})
print(result)  # Output: Hello, World!

Usage

Basic Templating

from handlebarrz import Template

template = Template()

# Simple variable substitution
template.register_template('simple', 'Welcome, {{user}}!')
print(template.render('simple', {'user': 'Alice'}))
# Output: Welcome, Alice!

# Nested properties
template.register_template('nested', '{{person.name}} is {{person.age}} years old')
print(template.render('nested', {'person': {'name': 'Bob', 'age': 30}}))
# Output: Bob is 30 years old

Built-in Helpers

# Conditionals
template.register_template(
    'conditional',
    """
{{#if active}}
  User is active
{{else}}
  User is inactive
{{/if}}
""",
)

# Iteration
template.register_template(
    'list',
    """
{{#each items}}
  - {{this}}
{{/each}}
""",
)

# With helper for context switching
template.register_template(
    'with',
    """
{{#with user}}
  Name: {{name}}, Email: {{email}}
{{/with}}
""",
)

Custom Helpers

from handlebarrz import HelperOptions, Template

template = Template()


# Register a custom helper
def format_name(params: list[object], options: HelperOptions) -> str:
    name = str(params[0]) if params else ''
    return name.upper() if options.hash_value('uppercase') else name


template.register_helper('format', format_name)
template.register_template('custom', '{{format name uppercase=true}}')
print(template.render('custom', {'name': 'alice'}))
# Output: ALICE

HelperOptions is callback-scoped; do not retain it for later use or access it from background work.

Partials

template = Template()

# Register a partial
template.register_partial('header', '<h1>{{title}}</h1>')
template.register_template('page', '{{> header}}<p>{{content}}</p>')
print(template.render('page', {'title': 'Welcome', 'content': 'Hello!'}))
# Output: <h1>Welcome</h1><p>Hello!</p>

HTML Escaping

template = Template()

# HTML is escaped by default
template.register_template('escaped', '{{content}}')
print(template.render('escaped', {'content': "<script>alert('xss')</script>"}))
# Output: &lt;script&gt;alert(&#x27;xss&#x27;)&lt;/script&gt;

# Use triple braces for raw output
template.register_template('raw', '{{{content}}}')
print(template.render('raw', {'content': '<b>bold</b>'}))
# Output: <b>bold</b>

API Reference

Template Class

Method Description
register_template(name, source) Register a template with a name
render(name, context) Render a registered template with context
render_template(source, context) Render a template string directly
register_helper(name, func) Register a custom helper accepting (params, options)
register_partial(name, source) Register a partial template
unregister_template(name) Remove a registered template
set_strict_mode(enabled) Enable/disable strict mode
set_dev_mode(enabled) Enable/disable development mode

Part of Dotprompt

This package is part of the Dotprompt project, providing the Handlebars templating engine for the dotpromptz Python package. While primarily designed for Dotprompt, it can be used as a standalone Handlebars implementation for Python.

License

Apache-2.0

Metadata

Release files for dotpromptz-handlebars 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for dotpromptz-handlebars 0.1.9
File Interpreter ABI Platform
dotpromptz_handlebars-0.1.9-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Release files / dotpromptz_handlebars-0.1.9-cp310-abi3-macosx_10_12_x86_64.whl

Download URL dotpromptz_handlebars-0.1.9-cp310-abi3-macosx_10_12_x86_64.whl
Size 515.6 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
b5511295693b94de290d856c424535de3aaa6c7764cd0e0c5d8ec09e1f56fd61
BLAKE2b-256 checksum
How to use checksums
0c7944829a343253038c1bd88b1d2a55ecae249056f1d6ac898a67a98f53fdba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.9 This release

1 release file

0.1.8

38 release files

0.1.7

38 release files

0.1.5

38 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page