mstache


Namemstache JSON
Version 0.3.0 PyPI version JSON
download
home_pagehttps://gitlab.com/ergoithz/mstache
Summarymstache, Mustache for Python
upload_time2024-10-12 21:57:00
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.
            # mstache

Mustache for Python.

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

## License

[MIT License](https://gitlab.com/ergoithz/mstache/-/blob/master/LICENSE)

## Installation

```python
pip install mstache
```

## Usage

Python:

```python
import mstache

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

Command line:

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

## Highlights

- The fastest pure-python Mustache implementation to this date.
- High [mustache.js](https://github.com/janl/mustache.js) compatibility.
- Fully spec compliant up to [Mustache v1.4.2](https://github.com/mustache/spec/releases/tag/v1.4.2),
  including lambda extension (opt-in).
- Support for [chevron](https://github.com/kholmogorov27/chevron)-style lambdas (opt-out)
- Command line interface.
- Small codebase, efficiently rendering to `str` or `bytes`, buffered or stream.
- Fully customizable behavior for caching, property getter, partial resolver,
  stringification, escaping, chevron lambda render and mustache block line
  trimming.
- Support for binary templates (`bytes` and `keep_lines` option).
- No dynamic code generation, both jit and transpiler friendly.

## Considerations

For inter-compatibility with JavaScript (especially [mustache.js](https://github.com/janl/mustache.js),
to enable client-side rendering the same templates), **mstache** must behave
somewhat atypically for a `Python` template engine:

- Mustache blocks stick to JavaScript truthyness:
  - Empty mappings (such as `dict`) are unconditionally truthy.
  - `NaN`/`-NaN` are falsy.
- Mustache blocks do not iterate mappings nor strings.
- Sized collections, excluding mappings, will expose a virtual `length` property,
  customizable via `getter` parameter.
- Mapping keys containing dot (`.`) or whitespace (` `) are unreachable
  (common property 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.

An special consideration about the Mustache spec: **mstache** currently passes
most [mustache spec](https://github.com/mustache/spec) tests (plus optional lambdas)
[but one](https://github.com/mustache/spec/blob/66f078e0d534515d8df23d0d3764dccda74e042b/specs/interpolation.yml#L198-L204)
to ensure [mustache.js](https://github.com/janl/mustache.js) compatibility.

## 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
$ mstache -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/mstache",
    "name": "mstache",
    "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/6c/3a/a0d22da35675d328ff45c29b35bb0e90b0ea3ff72f7cd7e679e3d383eb6a/mstache-0.3.0.tar.gz",
    "platform": "any",
    "description": "# mstache\n\nMustache for Python.\n\nDocumentation: [mstache.readthedocs.io](https://mstache.readthedocs.io)\n\n## License\n\n[MIT License](https://gitlab.com/ergoithz/mstache/-/blob/master/LICENSE)\n\n## Installation\n\n```python\npip install mstache\n```\n\n## Usage\n\nPython:\n\n```python\nimport mstache\n\nprint(mstache.render('Hello {{v}}', {'v': 'World!'}))\n# Hello World!\n```\n\nCommand line:\n\n```sh\n$ mstache -j data.json -o output.html template.mustache\n```\n\n## Highlights\n\n- The fastest pure-python Mustache implementation to this date.\n- High [mustache.js](https://github.com/janl/mustache.js) compatibility.\n- Fully spec compliant up to [Mustache v1.4.2](https://github.com/mustache/spec/releases/tag/v1.4.2),\n  including lambda extension (opt-in).\n- Support for [chevron](https://github.com/kholmogorov27/chevron)-style lambdas (opt-out)\n- Command line interface.\n- Small codebase, efficiently rendering to `str` or `bytes`, buffered or stream.\n- Fully customizable behavior for caching, property getter, partial resolver,\n  stringification, escaping, chevron lambda render and mustache block line\n  trimming.\n- Support for binary templates (`bytes` and `keep_lines` option).\n- No dynamic code generation, both jit and transpiler friendly.\n\n## Considerations\n\nFor inter-compatibility with JavaScript (especially [mustache.js](https://github.com/janl/mustache.js),\nto enable client-side rendering the same templates), **mstache** must behave\nsomewhat atypically for a `Python` template engine:\n\n- Mustache blocks stick to JavaScript truthyness:\n  - Empty mappings (such as `dict`) are unconditionally truthy.\n  - `NaN`/`-NaN` are falsy.\n- Mustache blocks do not iterate mappings nor strings.\n- Sized collections, excluding mappings, will expose a virtual `length` property,\n  customizable via `getter` parameter.\n- Mapping keys containing dot (`.`) or whitespace (` `) are unreachable\n  (common property limitation), 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), customizable via `getter` parameter.\n\nAn special consideration about the Mustache spec: **mstache** currently passes\nmost [mustache spec](https://github.com/mustache/spec) tests (plus optional lambdas)\n[but one](https://github.com/mustache/spec/blob/66f078e0d534515d8df23d0d3764dccda74e042b/specs/interpolation.yml#L198-L204)\nto ensure [mustache.js](https://github.com/janl/mustache.js) compatibility.\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$ mstache -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": "mstache, Mustache for Python",
    "version": "0.3.0",
    "project_urls": {
        "Homepage": "https://gitlab.com/ergoithz/mstache"
    },
    "split_keywords": [
        "template",
        " mustache"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6db03742108cf5a2e24edab4e0ac24db9a3858803497e2385270f78a7ed3c525",
                "md5": "66e31c59075432669661e14b978e7fb5",
                "sha256": "17a53df221fe7cab18bf2250db4ed003db5f5e06d84cf41b1c5caeea6da50cf9"
            },
            "downloads": -1,
            "filename": "mstache-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "66e31c59075432669661e14b978e7fb5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10.0",
            "size": 14306,
            "upload_time": "2024-10-12T21:56:58",
            "upload_time_iso_8601": "2024-10-12T21:56:58.835933Z",
            "url": "https://files.pythonhosted.org/packages/6d/b0/3742108cf5a2e24edab4e0ac24db9a3858803497e2385270f78a7ed3c525/mstache-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6c3aa0d22da35675d328ff45c29b35bb0e90b0ea3ff72f7cd7e679e3d383eb6a",
                "md5": "a6f9437ae658551bc534299ff80550b7",
                "sha256": "1d72368d1cd46a3721f7f7bbe18aa602d19d063ca0d63b164c1ab75c8c410e52"
            },
            "downloads": -1,
            "filename": "mstache-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a6f9437ae658551bc534299ff80550b7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10.0",
            "size": 18044,
            "upload_time": "2024-10-12T21:57:00",
            "upload_time_iso_8601": "2024-10-12T21:57:00.739577Z",
            "url": "https://files.pythonhosted.org/packages/6c/3a/a0d22da35675d328ff45c29b35bb0e90b0ea3ff72f7cd7e679e3d383eb6a/mstache-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-12 21:57:00",
    "github": false,
    "gitlab": true,
    "bitbucket": false,
    "codeberg": false,
    "gitlab_user": "ergoithz",
    "gitlab_project": "mstache",
    "lcname": "mstache"
}
        
Elapsed time: 0.94857s