Skip to main content

Type inference for Jinja2 templates.

Project description

Build Status Coverage PyPI Version PyPI Downloads

Demo | Documentation | GitHub | PyPI

A library that provides a heuristic type inference algorithm for Jinja2 templates.

>>> from jinja2schema import infer, to_json_schema
>>> s = infer('{{ (x.a.b|first).name }}')
>>> s
{'x': {'a': {'b': [{'name': <scalar>}]}}

>>> s = infer('''
... {% for x in xs %}
...   {{ x }}
... {% endfor %}
''')
>>> s
{'xs': [<scalar>]}
>>> to_json_schema(s)
{
    'type': 'object',
    'required': ['xs'],
    'properties': {
        'xs': {
            'type': 'array'
            'title': 'xs',
            'items': {
                'title': 'x',
                'anyOf': [
                    {'type': 'string'},
                    {'type': 'number'},
                    {'type': 'boolean'},
                    {'type': 'null'}
                ],
            },
        }
    }
}

More examples can be found at the demo page.

Installing

pip install jinja2schema

License

BSD license

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jinja2schema-0.1.3.tar.gz (19.2 kB view details)

Uploaded Source

File details

Details for the file jinja2schema-0.1.3.tar.gz.

File metadata

File hashes

Hashes for jinja2schema-0.1.3.tar.gz
Algorithm Hash digest
SHA256 df60deba5d2b4a82a1bc042e20011559f370106aaf3973f4e76f1aee7cdb42b3
MD5 cea07478ee10fb634e6e2eff6e5585a2
BLAKE2b-256 9f49aa8c77e9a3ccf51cbb721a4ad2fce49c5aff59f9ffb93e693c1f4954ea73

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page