skillfed

pybars3

Handlebars.js templating for Python 3 and 2

pybars3 v0.9.7 355.5K downloads/30d#7,289 on PyPI190
Copyleft license DORMANT released

What it is and what it does

Pybars3 is a Python implementation of the Handlebars.js templating language, designed to let you write templates once and use them on both server and client. It compiles Handlebars syntax into Python callables that render templates with data and custom helpers. The package supports a substantial subset of Handlebars features including block helpers, partials, dynamic partials, subexpressions, and scope accessors like @index and @root.

The library works by parsing template source into an abstract syntax tree, then generating Python code that renders the template. Helpers are Python functions that accept context and options; partials are pre-compiled template fragments. The package uses a strlist class (a list subclass with a __unicode__ method) to avoid quadratic string concatenation overhead during rendering. It is maintained pragmatically for server-client template sharing rather than as a comprehensive Handlebars port, so not all Handlebars 2.0 features are implemented.

Use it for:

  • Share template definitions between a Python backend and a JavaScript frontend without rewriting them.
  • Render server-side HTML using Handlebars syntax when you prefer it over Jinja2 or other Python templating languages.
  • Build custom template helpers in Python that integrate with Handlebars block syntax and context passing.
  • Precompile Handlebars templates on the server for distribution to client-side rendering.
  • Migrate from a Node.js Handlebars setup to Python while keeping template syntax consistent.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Pybars3 compiles and renders Handlebars.js templates in Python, allowing you to use the same template syntax on both server and client.

No—install friction is high (source-only distribution), maintenance is dormant (last release 2019-11-05), and Python version support is outdated (classifiers only list up to 3.4). The copyleft license also restricts proprietary modifications. Consider only if you have an existing codebase already using pybars3 or a specific requirement to share Handlebars templates with a legacy system.

Install

pybars3 on PyPI

pip

pip install pybars3

uv

uv add pybars3

poetry

poetry add pybars3

Installing pybars3

Before you install

High install friction due to source-only distribution (pybars3-0.9.7.tar.gz). Maintenance is dormant—last release was 2019-11-05, over 2474 days ago, though the repository remains active with a recent commit on 2024-07-09.

License in practice

Licensed under GNU Lesser General Public License version 3 (copyleft). Any derivative work or modification must be distributed under the same license; proprietary use of modifications is restricted.

Quickstart

from pybars import Compiler

compiler = Compiler()
source = u"{{#list people}}{{firstName}} {{lastName}}{{/list}}"
template = compiler.compile(source)

def _list(this, options, items):
    result = [u'']
    for thing in items:
        result.extend(options['fn'](thing))
    return result

output = template(
    {'people': [{'firstName': 'John', 'lastName': 'Doe'}]},
    helpers={'list': _list}
)

Requires PyMeta3 as a runtime dependency; source distribution requires a build environment.

Verify before relying

  • Whether PyMeta3 is reliably available and maintained for modern Python versions.
  • Current compatibility with Python versions beyond 3.4 (classifiers list only up to 3.4).
  • Whether all Handlebars 2.0 features are fully implemented or if gaps remain as noted in the description.

Package facts

License not declared (copyleft)
Python support not specified
Install friction high — source build required
Runtime dependencies none
Maintenance dormant — 2,474 days since the last release
Last repo commit
First released
Downloads 355,539/month — #7,289 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: pybars3-0.9.7.tar.gz

Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)Operating System :: OS IndependentProgramming Language :: Python :: 2Programming Language :: Python :: 2.7Programming Language :: Python :: 3Programming Language :: Python :: 3.3Programming Language :: Python :: 3.4

Tags

handlebars template engine pythonhandlebars.js python implementationtemplate rendering pythonshared templates server clientmustache alternative pythonhandlebars compiler python
template-enginehandlebarsdormant

More Markup packages