ustache, Mustache for Python
Project description
ustache
Mustache for Python.
Documentation: ustache.readthedocs.io
Usage
import ustache
print(ustache.render('Hello {{v}}', {'v': 'World!'}))
# Hello World!
Command line:
$ ustache -j data.json -o output.html template.mustache
Highlights
- Command line interface.
- Spec compliant, but also highly compatible with
Mustache.js. - Fast and small codebase, efficiently rendering to str or bytes, supporting streaming.
- Customizable (property getter, partial resolver, and stringify, escape and lambda render functions).
Considerations
For inter-compatibility with JavaScript (enabling client-side rendering with the same templates), ustache made some deliberate behavior choices:
- Mustache blocks stick to JavaScript falseness (
__bool__is not honored):None,False,0,nan, and empty sequences (including strings) are taken as falsy, while everything else (including empty mappings) will be considered truthy (Mustache.jsBooleanand emptyArrayhandling). - Mustache blocks receiving any iterable other than mappings and strings
will result on a loop (Mustache.js
Arrayhandling). - Sequences expose a virtual
lengthproperty (JavaScriptArray.lengthemulation). - Sequence elements are accessible by positive index in the same way mapping
integer-keyed items are also accessible if no string key conflicts, as
properties (JavaScript
Objectemulation).
Syntax
Check out the mustache(5) manual.
For quick reference, here is a quick overview of the Mustache syntax.
Template:
{{!comment}}
<ul>
{{#object}}<li>{{property}}</li>{{/object}}
{{^object}}<li>As <b>object</b> is truthy, this won't be shown</li>{{/object}}
{{^null}}<li><b>null</b> is falsy</li>{{/null}}
{{#array}}<li>{{property}}</li>
{{/array}}
{{^array}}<li>Array isn't empty, this won't be shown.</li>{{/array}}
{{#empty_array}}<li>Empty Array, this won't be shown</li>{{/empty_array}}
{{^empty_array}}<li>empty_array is empty</li>{{/empty_array}}
{{&unescaped_html}}
</ul>
Data:
{
"object": {
"property": "Object property value"
},
"null": null,
"array": [
{"property": "Array item1 property"},
{"property": "Array item2 property"},
{"property": "Array item3 property"}
],
"empty_array": [],
"unescaped_html": "<li>this is unescaped html</li>"
}
Output:
<ul>
<li>Object property value</li>
<li><b>null</b> is falsy</li>
<li>Array item1 property</li>
<li>Array item2 property</li>
<li>Array item3 property</li>
<li>empty_array is empty</li>
<li>this is unescaped html</li>
</ul>
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ustache-0.1.0.tar.gz.
File metadata
- Download URL: ustache-0.1.0.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
baf41c854a12ab04ced81cfbee37397de4cd81ba4a31b3f275eaabeff0e8b6cb
|
|
| MD5 |
84f44986e52c0a8bf8bb026b4adf29a6
|
|
| BLAKE2b-256 |
9b4707b5c8e3a983c79be0e79ba396b47cdb683eaa7a3d8f6b54e2f0a702d97b
|
File details
Details for the file ustache-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ustache-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12fd4a36a0d15418feeb8b86fae06e2cecc07a0cff0dfb0810862449c34767c2
|
|
| MD5 |
dbec0cda85d8ae59befa70975f663462
|
|
| BLAKE2b-256 |
ba9a8159ebbcaa13649938caacfd95cebde4f5bfdb57e870fc65726226d3db20
|