ustache


Nameustache JSON
Version 0.1.6 PyPI version JSON
download
home_pagehttps://gitlab.com/ergoithz/ustache
Summaryustache, Mustache for Python
upload_time2024-09-19 23:08:39
maintainerNone
docs_urlNone
authorFelipe A Hernandez
requires_python>=3.10.0
licenseMIT
keywords template mustache
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ustache (deprecated)

Mustache for Python, backwards-compatible wrapper of [mstache](https://gitlab.com/ergoithz/mstache).

- Current documentation (mustache): [mstache.readthedocs.io](https://mstache.readthedocs.io)
- Old documentation: [ustache.readthedocs.io](https://ustache.readthedocs.io)

> :warning: Development moved over to [mstache](https://gitlab.com/ergoithz/mstache),

## Installation

```sh
$ 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": null,
    "docs_url": null,
    "requires_python": ">=3.10.0",
    "maintainer_email": null,
    "keywords": "template, mustache",
    "author": "Felipe A Hernandez",
    "author_email": "ergoithz@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/2f/61/3bb1a3d8a7ca9db719240b57341ecbe50e43b8e01c9f16bcce3d564ea8ff/ustache-0.1.6.tar.gz",
    "platform": "any",
    "description": "# ustache (deprecated)\n\nMustache for Python, backwards-compatible wrapper of [mstache](https://gitlab.com/ergoithz/mstache).\n\n- Current documentation (mustache): [mstache.readthedocs.io](https://mstache.readthedocs.io)\n- Old documentation: [ustache.readthedocs.io](https://ustache.readthedocs.io)\n\n> :warning: Development moved over to [mstache](https://gitlab.com/ergoithz/mstache),\n\n## Installation\n\n```sh\n$ pip 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",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "ustache, Mustache for Python",
    "version": "0.1.6",
    "project_urls": {
        "Homepage": "https://gitlab.com/ergoithz/ustache"
    },
    "split_keywords": [
        "template",
        " mustache"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8c5babb369b53317b034a69d4d3668395a0a01e29dd188910983d116d84f3fb4",
                "md5": "d5e6f0919beb3642f626c8ae28b3cae0",
                "sha256": "5f8bec2478abd8a779a2b596dd1c9074b6a18d6f4fecfc2f9dedc24104783e1f"
            },
            "downloads": -1,
            "filename": "ustache-0.1.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d5e6f0919beb3642f626c8ae28b3cae0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10.0",
            "size": 6827,
            "upload_time": "2024-09-19T23:08:37",
            "upload_time_iso_8601": "2024-09-19T23:08:37.484068Z",
            "url": "https://files.pythonhosted.org/packages/8c/5b/abb369b53317b034a69d4d3668395a0a01e29dd188910983d116d84f3fb4/ustache-0.1.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2f613bb1a3d8a7ca9db719240b57341ecbe50e43b8e01c9f16bcce3d564ea8ff",
                "md5": "af01eae768c20f2b1701409548feb079",
                "sha256": "ad00bea46d89a1c8386650e694180665138b10dd8ae1ddd32ae5c6e67531c908"
            },
            "downloads": -1,
            "filename": "ustache-0.1.6.tar.gz",
            "has_sig": false,
            "md5_digest": "af01eae768c20f2b1701409548feb079",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10.0",
            "size": 7759,
            "upload_time": "2024-09-19T23:08:39",
            "upload_time_iso_8601": "2024-09-19T23:08:39.050547Z",
            "url": "https://files.pythonhosted.org/packages/2f/61/3bb1a3d8a7ca9db719240b57341ecbe50e43b8e01c9f16bcce3d564ea8ff/ustache-0.1.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-19 23:08:39",
    "github": false,
    "gitlab": true,
    "bitbucket": false,
    "codeberg": false,
    "gitlab_user": "ergoithz",
    "gitlab_project": "ustache",
    "lcname": "ustache"
}
        
Elapsed time: 1.30658s