跳转到主要内容

Jinja2模板的类型推断。

项目描述

Build Status Coverage PyPI Version PyPI Downloads

演示 | 文档 | GitHub | PyPI

一个为Jinja2模板提供启发式类型推断算法的库。

>>> 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'}
                ],
            },
        }
    }
}

更多示例可以在演示页面找到。

安装

pip install jinja2schema

许可

BSD许可

项目详情


下载文件

下载适合您平台的应用程序。如果您不确定选择哪个,请了解有关安装软件包的更多信息。

源分发

jinja2schema-0.1.4.tar.gz (19.8 kB 查看哈希值)

上传时间: 源代码

支持者