Registry / serialization / pybars4

pybars4

JSON →
library0.9.13pypypi✓ verified 88d ago

PyBars4 is a Python 3 implementation of the popular Handlebars.js templating language. It allows developers to compile and render Handlebars templates within Python applications. The library is currently at version 0.9.13 and has an active, though somewhat sporadic, release cadence with recent updates focusing on bug fixes and changes to HTML escaping behavior.

pip install pybars4
INSTALL
IMPORT
SIG · PYBARS4
P
pybars4
serializationpythonv0.9.13
Install
3.1s avg
Import
1864ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.9.13 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 1.931s · 19.4MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 3.1s · import 1.797s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Compiler
✓ from pybars import Compiler
✗ from pybars4 import Compiler
The PyPI package name is 'pybars4', but the top-level import module is 'pybars'.

This quickstart demonstrates compiling a basic Handlebars template and rendering it with a Python dictionary context.

from pybars import Compiler compiler = Compiler() source = u"Hello {{name}}!" template = compiler.compile(source) context = {'name': "World"} result = template(context) print(result) # Expected: Hello World!
Debug
Known issues
breakingHTML escaping was explicitly disabled by default in version 0.9.10. If your templates contain user-generated content and you relied on PyBars4 to automatically escape HTML, this change can introduce XSS vulnerabilities.
fix
Manually escape variables using custom helpers or ensure all data passed to templates is already safe/sanitized before rendering. Review the security implications of this change carefully.
affects: 0.9.10+
gotchaThe PyPI package is named `pybars4`, but the Python module to import is `pybars`.
fix
Always use `from pybars import ...` or `import pybars` in your code after installing `pybars4`.
affects: All versions
gotchaPyBars4 is a Python 3 specific library and does not support Python 2.
fix
Ensure your project runs on Python 3. If you require Python 2 compatibility, you will need to find an alternative templating engine or use an older, unmaintained version of PyBars (not PyBars4).
affects: All versions
gotchaContext handling can sometimes differ from JavaScript Handlebars, especially with complex Python objects vs. simple dictionaries. Issues like 'undefined object attributes' can occur if data access patterns don't match expectations.
fix
Ensure that your context dictionaries or objects provide the attributes/keys that the Handlebars template expects. For complex objects, you might need to implement custom helper functions to expose data correctly within the template.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pybars4'
You are trying to import from 'pybars4', but the correct module name is 'pybars'.
fix
Change your import statement from `from pybars4 import ...` to `from pybars import ...`.
TypeError: 'Compiler' object is not callable
You are attempting to call the `Compiler` class instance directly, instead of its `compile` method.
fix
Ensure you are calling `compiler.compile(source)` to compile your template source string, where `compiler` is an instance of `Compiler`.
Template rendering outputs unescaped HTML or introduces XSS vulnerabilities after upgrading
Version 0.9.10 and later disabled default HTML escaping. Your application now relies on this behavior and might be vulnerable.
fix
Either manually escape all template variables (e.g., using a custom helper if available) or sanitize your input data before passing it to the template. Review the security implications of this change carefully.
Upgrade
Version history
0.9.13latest on PyPI · released Apr 4, 2021
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
pybars4 — pip install pybars4 · libregistry