ustache


Nameustache JSON
Version 0.1.5 PyPI version JSON
download
home_pagehttps://gitlab.com/ergoithz/ustache
Summaryustache, Mustache for Python
upload_time2021-12-17 16:58:37
maintainer
docs_urlNone
authorFelipe A Hernandez
requires_python>=3.6.0
licenseMIT
keywords template mustache
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ustache

Mustache for Python.

Documentation: [ustache.readthedocs.io](https://ustache.readthedocs.io)

## Installation

```python
pip install ustache
```

## Usage

Python:

```python
import ustache

print(ustache.render('Hello {{v}}', {'v': 'World!'}))
# Hello World!
```

Command line:

```sh
$ ustache -j data.json -o output.html template.mustache
```

## Highlights

- The fastest pure-python Mustache implementation to this date.
- Command line interface.
- Spec compliant, but also highly compatible with `Mustache.js`.
- Small codebase, efficiently rendering to `str` or `bytes`,
  supporting streaming.
- Customizable (property getter, partial resolver, and stringify, escape
  and lambda render functions).
- Customizable template caching, with an optional memory-efficient mode
  (see [xxhash optional dependency below](#xxhash)).
- No dynamic code generation, jit and transpiler friendly.

## Considerations

For inter-compatibility with JavaScript (especially `Mustache.js`, enabling
client-side rendering with the same templates), **ustache** exposes 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.js` `Boolean` and empty `Array` handling).
- Mustache blocks receiving any iterable other than mappings and strings
  will result on a loop (`Mustache.js` `Array` handling).
- Non-mapping sized objects will expose a virtual `length` property
  (JavaScript `Array.length` emulation).
  Customizable via `getter` parameter.
- Mapping keys containing dot (`.`) or whitespace (` `) are unreachable,
  (`Mustache.js` property name limitation).
  Customizable via `getter` parameter.
- 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 (JavaScript `Object` emulation).
  Customizable via `getter` parameter.

## Optional dependencies

For minimalism and portability, **ustache** has no hard dependencies, while
still supporting some libraries for added functionality:

- <a id="xxhash"></a>[xxhash](https://pypi.org/project/xxhash)
  will 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 using **ustache** `optional` extra target:

```sh
$ pip install ustache[optional]
```

## Syntax

Check out the [mustache(5) manual](https://mustache.github.io/mustache.5.html).

For quick reference, here is a quick overview of the Mustache syntax.

Template (`template.mustache`):
```handlebars
{{!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`):
```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:
```sh
$ ustache -j data.json -o output.html template.mustache
```

Output:
```html
<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>
```



            

Raw data

            {
    "_id": null,
    "home_page": "https://gitlab.com/ergoithz/ustache",
    "name": "ustache",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6.0",
    "maintainer_email": "",
    "keywords": "template,mustache",
    "author": "Felipe A Hernandez",
    "author_email": "ergoithz@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/d2/78/8ded586be90aca0bbdc939654648046575067affcf82c649b06ec21f7b5c/ustache-0.1.5.tar.gz",
    "platform": "any",
    "description": "# ustache\n\nMustache for Python.\n\nDocumentation: [ustache.readthedocs.io](https://ustache.readthedocs.io)\n\n## Installation\n\n```python\npip install ustache\n```\n\n## Usage\n\nPython:\n\n```python\nimport ustache\n\nprint(ustache.render('Hello {{v}}', {'v': 'World!'}))\n# Hello World!\n```\n\nCommand line:\n\n```sh\n$ ustache -j data.json -o output.html template.mustache\n```\n\n## Highlights\n\n- The fastest pure-python Mustache implementation to this date.\n- Command line interface.\n- Spec compliant, but also highly compatible with `Mustache.js`.\n- Small codebase, efficiently rendering to `str` or `bytes`,\n  supporting streaming.\n- Customizable (property getter, partial resolver, and stringify, escape\n  and lambda render functions).\n- Customizable template caching, with an optional memory-efficient mode\n  (see [xxhash optional dependency below](#xxhash)).\n- No dynamic code generation, jit and transpiler friendly.\n\n## Considerations\n\nFor inter-compatibility with JavaScript (especially `Mustache.js`, enabling\nclient-side rendering with the same templates), **ustache** exposes some\natypical behavior:\n\n- Mustache blocks stick to JavaScript falseness (`__bool__` is not honored):\n  `None`, `False`, `0`, `nan`, and empty sequences (including strings)\n  are taken as falsy, while everything else (including empty mappings) will\n  be considered truthy (`Mustache.js` `Boolean` and empty `Array` handling).\n- Mustache blocks receiving any iterable other than mappings and strings\n  will result on a loop (`Mustache.js` `Array` handling).\n- Non-mapping sized objects will expose a virtual `length` property\n  (JavaScript `Array.length` emulation).\n  Customizable via `getter` parameter.\n- Mapping keys containing dot (`.`) or whitespace (` `) are unreachable,\n  (`Mustache.js` property name limitation).\n  Customizable via `getter` parameter.\n- Sequence elements are accessible by positive index in the same way mapping\n  integer-keyed items are also accessible when no string key conflicts, as\n  properties (JavaScript `Object` emulation).\n  Customizable via `getter` parameter.\n\n## Optional dependencies\n\nFor minimalism and portability, **ustache** has no hard dependencies, while\nstill supporting some libraries for added functionality:\n\n- <a id=\"xxhash\"></a>[xxhash](https://pypi.org/project/xxhash)\n  will be used, if available, to avoid storing the whole template data as\n  part of the template cache, dramatically reducing its memory footprint in\n  many situations.\n\nOptional but generally recommended dependencies can be easily installed\nall at once using **ustache** `optional` extra target:\n\n```sh\n$ pip install ustache[optional]\n```\n\n## Syntax\n\nCheck out the [mustache(5) manual](https://mustache.github.io/mustache.5.html).\n\nFor quick reference, here is a quick overview of the Mustache syntax.\n\nTemplate (`template.mustache`):\n```handlebars\n{{!comment}}\n<ul>\n{{#object}}<li>{{property}}</li>{{/object}}\n{{^object}}<li>As <b>object</b> is truthy, this won't be shown</li>{{/object}}\n{{^null}}<li><b>null</b> is falsy</li>{{/null}}\n{{#array}}<li>{{property}}</li>\n{{/array}}\n{{^array}}<li>Array isn't empty, this won't be shown.</li>{{/array}}\n{{#empty_array}}<li>Empty Array, this won't be shown</li>{{/empty_array}}\n{{^empty_array}}<li>empty_array is empty</li>{{/empty_array}}\n{{&unescaped_html}}\n</ul>\n```\n\nData (`data.json`):\n```json\n{\n  \"object\": {\n    \"property\": \"Object property value\"\n  },\n  \"null\": null,\n  \"array\": [\n    {\"property\": \"Array item1 property\"},\n    {\"property\": \"Array item2 property\"},\n    {\"property\": \"Array item3 property\"}\n  ],\n  \"empty_array\": [],\n  \"unescaped_html\": \"<li>this is unescaped html</li>\"\n}\n```\n\nCommand:\n```sh\n$ ustache -j data.json -o output.html template.mustache\n```\n\nOutput:\n```html\n<ul>\n<li>Object property value</li>\n<li><b>null</b> is falsy</li>\n<li>Array item1 property</li>\n<li>Array item2 property</li>\n<li>Array item3 property</li>\n<li>empty_array is empty</li>\n<li>this is unescaped html</li>\n</ul>\n```\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "ustache, Mustache for Python",
    "version": "0.1.5",
    "project_urls": {
        "Homepage": "https://gitlab.com/ergoithz/ustache"
    },
    "split_keywords": [
        "template",
        "mustache"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ae0ddcfe8116c9f31cb251c372742807a15abce28d1efeb2f3c6a7554cbad17f",
                "md5": "c7b33298dfff95294abea442bbbb6f11",
                "sha256": "3d277909dd7bc3012eee101ffa68a241f66222b768fe1c7c77afff9a1d2028fc"
            },
            "downloads": -1,
            "filename": "ustache-0.1.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c7b33298dfff95294abea442bbbb6f11",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6.0",
            "size": 12415,
            "upload_time": "2021-12-17T16:58:35",
            "upload_time_iso_8601": "2021-12-17T16:58:35.533784Z",
            "url": "https://files.pythonhosted.org/packages/ae/0d/dcfe8116c9f31cb251c372742807a15abce28d1efeb2f3c6a7554cbad17f/ustache-0.1.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d2788ded586be90aca0bbdc939654648046575067affcf82c649b06ec21f7b5c",
                "md5": "09669d65fb3f88eb11201bb9fb1d3d7c",
                "sha256": "effd84a47a495ad9cda9613dc2d27f13b7ad5c3cd60c86243bfb0df14d366648"
            },
            "downloads": -1,
            "filename": "ustache-0.1.5.tar.gz",
            "has_sig": false,
            "md5_digest": "09669d65fb3f88eb11201bb9fb1d3d7c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6.0",
            "size": 12910,
            "upload_time": "2021-12-17T16:58:37",
            "upload_time_iso_8601": "2021-12-17T16:58:37.192888Z",
            "url": "https://files.pythonhosted.org/packages/d2/78/8ded586be90aca0bbdc939654648046575067affcf82c649b06ec21f7b5c/ustache-0.1.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-12-17 16:58:37",
    "github": false,
    "gitlab": true,
    "bitbucket": false,
    "codeberg": false,
    "gitlab_user": "ergoithz",
    "gitlab_project": "ustache",
    "lcname": "ustache"
}
        
Elapsed time: 0.07571s