Package: ustache
ustacheMustache for Python.Documentation:ustache.readthedocs.ioInstallationpipinstallustacheUsagePython:importustacheprint(ustache.render('Hello {{v}}',{'v':'World!'}))# Hello World!Command line:$ustache-jdata.json-ooutput.htmltemplate.mustacheHighlightsThe fastest pure-python Mustache implementation to this date.Command line interface.Spec compliant, but also highly compatible withMustache.js.Small codebase, efficiently rendering tostrorbytes,
supporting streaming.Customizable (property getter, partial resolver, and stringify, escape
and lambda render functions).Customizable template caching, with an optional memory-efficient mode
(seexxhash optional dependency below).No dynamic code generation, jit and transpiler friendly.ConsiderationsFor inter-compatibility with JavaScript (especiallyMustache.js, enabling
client-side rendering with the same templates),ustacheexposes some
atypical behavior: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.jsArrayhandling).Non-mapping sized objects will expose a virtuallengthproperty
(JavaScriptArray.lengthemulation).
Customizable viagetterparameter.Mapping keys containing dot (.) or whitespace () are unreachable,
(Mustache.jsproperty name limitation).
Customizable viagetterparameter.Sequence elements are accessible by positive index in the same way mapping
integer-keyed items are also accessible when no string key conflicts, as
properties (JavaScriptObjectemulation).
Customizable viagetterparameter.Optional dependenciesFor minimalism and portability,ustachehas no hard dependencies, while
still supporting some libraries for added functionality:xxhashwill be used, if available, to avoid storing the whole template data as
part of the template cache, dramatically reducing its memory footprint in
many situations.Optional but generally recommended dependencies can be easily installed
all at once usingustacheoptionalextra target:$pipinstallustache[optional]SyntaxCheck out themustache(5) manual.For quick reference, here is a quick overview of the Mustache syntax.Template (template.mustache):{{!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 (data.json):{"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>"}Command:$ustache-jdata.json-ooutput.htmltemplate.mustacheOutput:<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>