freshcrate
Home > Frameworks > pystache

pystache

Mustache for Python

Description

Pystache ======== |ci| |conda| |coverage| |bandit| |release| |pre| |cov| |pylint| |tag| |license| |python| This updated fork of Pystache is currently tested on Python 3.8+ and in Conda, on Linux, Macos, and Windows. |logo| `Pystache <https://github.com/PennyDreadfulMTG/pystache>`__ is a Python implementation of `Mustache <https://github.com/mustache/mustache/>`__. Mustache is a framework-agnostic, logic-free templating system inspired by `ctemplate <https://code.google.com/p/google-ctemplate/>`__ and et. Like ctemplate, Mustache "emphasizes separating logic from presentation: it is impossible to embed application logic in this template language." The `mustache(5) <https://mustache.github.io/mustache.5.html>`__ man page provides a good introduction to Mustache's syntax. For a more complete (and more current) description of Mustache's behavior, see the official `Mustache spec <https://github.com/mustache/spec>`__. Pystache is `semantically versioned <https://semver.org>`__ and older versions can still be found on `PyPI <https://pypi.python.org/pypi/pystache>`__. This version of Pystache now passes all tests in `version 1.1.3 <https://github.com/mustache/spec/tree/v1.1.3>`__ of the spec. Requirements ============ Pystache is tested with: - Python 3.8 - Python 3.9 - Python 3.10 - Python 3.11 - Python 3.12 - Python 3.13 - Conda (py38 and py310) JSON support is needed only for the command-line interface and to run the spec tests; PyYAML can still be used (see the Develop section). Official support for Python 2 has ended with Pystache version 0.6.0. .. note:: This project uses setuptools_scm_ to generate and maintain the version file, which only gets included in the sdist/wheel packages. In a fresh clone, running any of the tox_ commands should generate the current version file. .. _setuptools_scm: https://github.com/pypa/setuptools_scm .. _tox: https://github.com/tox-dev/tox Quick Start =========== Be sure to get the latest release from either Pypi or Github. Install It ---------- From Pypi:: $ pip install pystache Or Github:: $ pip install -U pystache -f https://github.com/PennyDreadfulMTG/pystache/releases/ And test it:: $ pystache-test To install and test from source (e.g. from GitHub), see the Develop section. Use It ------ Open a python console:: >>> import pystache >>> print(pystache.render('Hi {{person}}!', {'person': 'Mom'})) Hi Mom! You can also create dedicated view classes to hold your view logic. Here's your view class (in ../pystache/tests/examples/readme.py): :: class SayHello(object): def to(self): return "Pizza" Instantiating like so: :: >>> from pystache.tests.examples.readme import SayHello >>> hello = SayHello() Then your template, say_hello.mustache (by default in the same directory as your class definition): :: Hello, {{to}}! Pull it together: :: >>> renderer = pystache.Renderer() >>> print(renderer.render(hello)) Hello, Pizza! For greater control over rendering (e.g. to specify a custom template directory), use the ``Renderer`` class like above. One can pass attributes to the Renderer class constructor or set them on a Renderer instance. To customize template loading on a per-view basis, subclass ``TemplateSpec``. See the docstrings of the `Renderer <https://github.com/PennyDreadfulMTG/pystache/blob/master/pystache/renderer.py>`__ class and `TemplateSpec <https://github.com/PennyDreadfulMTG/pystache/blob/master/pystache/template_spec.py>`__ class for more information. You can also pre-parse a template: :: >>> parsed = pystache.parse(u"Hey {{#who}}{{.}}!{{/who}}") >>> print(parsed) ['Hey ', _SectionNode(key='who', index_begin=12, index_end=18, parsed=[_EscapeNode(key='.'), '!'])] And then: :: >>> print(renderer.render(parsed, {'who': 'Pops'})) Hey Pops! >>> print(renderer.render(parsed, {'who': 'you'})) Hey you! Unicode ------- This section describes how Pystache handles unicode, strings, and encodings. Internally, Pystache uses `only unicode strings`_ (``str`` in Python 3). For input, Pystache accepts byte strings (``bytes`` in Python 3). For output, Pystache's template rendering methods return only unicode. .. _only unicode strings: https://docs.python.org/howto/unicode.html#tips-for-writing-unicode-aware-programs Pystache's ``Renderer`` class supports a number of attributes to control how Pystache converts byte strings to unicode on input. These include the ``file_encoding``, ``string_encoding``, and ``decode_errors`` attributes. The ``file_encoding`` attribute is the encoding the renderer uses to convert to unicode any files read from the file system. Similarly, ``string_encoding`` is the encoding the renderer uses to convert any other byte strings encountered during the rendering process into unicode (e.g. context values that are encoded byte strings). The ``decode_errors`` attribute is what the renderer passes as the ``errors`` argumen

Release History

VersionChangesUrgencyDate
0.6.8Imported from PyPI (0.6.8)Low4/21/2026
v0.6.8## What's Changed * pystache has been stable and out of beta a long time, update config to reflect by @bakert in https://github.com/PennyDreadfulMTG/pystache/pull/36 * feat: Supply ParsingError with additional information by @mykola-mokhnach-parloa in https://github.com/PennyDreadfulMTG/pystache/pull/37 ## New Contributors * @mykola-mokhnach-parloa made their first contribution in https://github.com/PennyDreadfulMTG/pystache/pull/37 **Full Changelog**: https://github.com/PennyDreadfulMTLow3/18/2025
v0.6.7## What's Changed * fix: fail on unmatched tags by @shklqm in https://github.com/PennyDreadfulMTG/pystache/pull/34 ## New Contributors * @shklqm made their first contribution in https://github.com/PennyDreadfulMTG/pystache/pull/34 **Full Changelog**: https://github.com/PennyDreadfulMTG/pystache/compare/v0.6.6...v0.6.7Low12/24/2024
v0.6.6## What's Changed * Update changelog for v0.6.5 a bit belatedly by @bakert in https://github.com/PennyDreadfulMTG/pystache/pull/29 * Update for Python 3.12 & 3.13 by @alvaro-crespo in https://github.com/PennyDreadfulMTG/pystache/pull/31 * v0.6.6 release by @bakert in https://github.com/PennyDreadfulMTG/pystache/pull/33 ## New Contributors * @alvaro-crespo made their first contribution in https://github.com/PennyDreadfulMTG/pystache/pull/31 **Full Changelog**: https://github.com/PennyDrLow12/12/2024
v0.6.5## What's Changed * Keep changelog up to date manually as I don't know how to autogenerate by @bakert in https://github.com/PennyDreadfulMTG/pystache/pull/24 * Refactored version bits to facilitate packaging by @sarnold in https://github.com/PennyDreadfulMTG/pystache/pull/28 **Full Changelog**: https://github.com/PennyDreadfulMTG/pystache/compare/v0.6.4...v0.6.5Low8/26/2023
v0.6.4## v0.6.4 (2023-08-13) ### Other * Merge pull request #23 from PennyDreadfulMTG/more-fixes. [Thomas David Baker] Use the content-type for RST that pypi now wants * Use the content-type for RST that pypi now wants. [Thomas David Baker] Low8/13/2023
v0.6.3## v0.6.3 (2023-08-13) ### New * Add full sphinx apidoc build, include readme/extras. [Stephen L Arnold] * add new tox commands for 'docs' and 'docs-lint' * cleanup link errors found by docs-lint * add sphinx doc build workflow, update ci workflow * remove new version var from __init__.py globals ### Changes * Display repo state in docs build, include CHANGELOG. [Stephen L Arnold] * add sphinx_git extension to docs conf and setup deps * display branch/commit/state docs were buiLow8/13/2023
v0.6.1### Changes * Add shallow checkout for testing. [Stephen L Arnold] * Bump comment action to latest release, verify checkout depth. [Stephen L Arnold] * see: https://github.com/marocchino/sticky-pull-request-comment/issues/298 in upstream action repo ### Fixes * Use workflow PR target and checkout params. [Stephen L Arnold] * Split coverage (checkout) job from PR comment job. [Stephen L Arnold] * Use correct tox env cmd for single platform/version. [Stephen L Arnold] Low11/24/2021
v0.6.0## (unreleased) ### Changes * Readme URLs => PennyDreadfulMTG. [Stephen L Arnold] * Bump spec versions to latest => v1.1.3. [Stephen L Arnold] * Update setup_description.rst for release. [Stephen L Arnold] * Update .setup_description.rst for packaging. [Stephen L Arnold] ### Fixes * Dev cleanup tests, create bandit baseline, allow one test item. [Stephen L Arnold] * fix spectesting with one baseline warning allowed * add baseline json file, add to args in tool cfgs * test bandit arLow11/7/2021

Dependencies & License Audit

Loading dependencies...

Similar Packages

pre-commitA framework for managing and maintaining multi-language pre-commit hooks.v4.6.0
azure-core-tracing-opentelemetryMicrosoft Azure Azure Core OpenTelemetry plugin Library for Pythonazure-template_0.1.0b6187637
spdx-toolsSPDX parser and tools.0.8.5
lacesDjango components that know how to render themselves.0.1.2
django-tasksA backport of Django's built in Tasks framework0.12.0