Type inference for Jinja2 templates.
Project description
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
Project details
Release history Release notifications | RSS feed
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.2.tar.gz
(19.1 kB
view details)
File details
Details for the file jinja2schema-0.1.2.tar.gz
.
File metadata
- Download URL: jinja2schema-0.1.2.tar.gz
- Upload date:
- Size: 19.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21f2c52bb0050584367ccf1c2edbd098db60e9c015a965ac98263c4bc4d9cd41 |
|
MD5 | 4b69a4594c9ca84b6c0bbb368e3064ce |
|
BLAKE2b-256 | a8d7a0ea1ac175b43046ce7725e88ae4ca1bb26511d27f083c9cc1728ed6ffe8 |