Skip to content

tiktuk/jinja2schema

 
 

Repository files navigation

jinja2schema

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

About

Type inference for Jinja2 templates

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 98.4%
  • HTML 1.5%
  • Shell 0.1%