Python Liquid模板语言的引擎。
项目描述
Python Liquid
Python Liquid是一个用于Liquid的Python引擎,它是灵活Web应用的客户端模板语言。
我们与Shopify/Liquid保持紧密跟踪,并针对Golden Liquid测试套件进行测试。
目录
安装
使用Pipenv安装Python Liquid
$ pipenv install -u python-liquid
或 pip
$ pip install python-liquid
$ conda install -c conda-forge python-liquid
链接
- 文档: https://jg-rp.github.io/liquid/
- 变更日志: https://github.com/jg-rp/liquid/blob/main/CHANGES.md
- PyPi: https://pypi.ac.cn/project/python-liquid/
- 源代码: https://github.com/jg-rp/liquid
- 问题跟踪器: https://github.com/jg-rp/liquid/issues
示例
from liquid import Template
template = Template("Hello, {{ you }}!")
print(template.render(you="World")) # "Hello, World!"
print(template.render(you="Liquid")) # "Hello, Liquid!"
相关项目
- liquid-babel Liquid模板的国际化和本地化。
- LiquidScript:与Python Liquid具有类似高级API的JavaScript和TypeScript引擎。
- django-liquid:Django模板后端,用于Liquid。在Django应用程序中渲染Liquid模板。
- Flask-Liquid:Flask扩展,用于Liquid。在Flask应用程序中渲染Liquid模板。
- golden-liquid:Liquid测试套件。查看各种Liquid模板引擎与参考实现之间的比较。
兼容性
我们力求与Ruby编写的Liquid参考实现100%兼容。也就是说,在相同的渲染上下文中,使用Python Liquid渲染的模板应与使用Ruby Liquid渲染的模板产生相同的结果。
请参阅已知问题页面,了解Python Liquid和Ruby Liquid之间已知的不兼容性,并在您发现不兼容性时请提出问题。
基准测试
您可以从源代码树的根目录运行hatch run benchmark
(如果您没有make
,可以使用python -O scripts/performance.py
)来进行基准测试。在我的Ryzen 5 1500X和Python 3.11.0的旧式台式电脑上,我们得到了以下结果。
Best of 5 rounds with 100 iterations per round and 60 ops per iteration (6000 ops per round).
lex template (not expressions): 1.2s (5020.85 ops/s, 83.68 i/s)
lex and parse: 5.0s (1197.32 ops/s, 19.96 i/s)
render: 1.4s (4152.92 ops/s, 69.22 i/s)
lex, parse and render: 6.5s (922.08 ops/s, 15.37 i/s)
PyPy3.7为我们提供了性能的适度提升。
Best of 5 rounds with 100 iterations per round and 60 ops per iteration (6000 ops per round).
lex template (not expressions): 0.58s (10308.67 ops/s, 171.81 i/s)
lex and parse: 3.6s (1661.20 ops/s, 27.69 i/s)
render: 0.95s (6341.14 ops/s, 105.69 i/s)
lex, parse and render: 4.6s (1298.18 ops/s, 21.64 i/s)
在相同的机器上,从参考实现源代码树的根目录运行rake benchmark:run
得到以下结果。
/usr/bin/ruby ./performance/benchmark.rb lax
Running benchmark for 10 seconds (with 5 seconds warmup).
Warming up --------------------------------------
parse: 3.000 i/100ms
render: 8.000 i/100ms
parse & render: 2.000 i/100ms
Calculating -------------------------------------
parse: 39.072 (± 0.0%) i/s - 393.000 in 10.058789s
render: 86.995 (± 1.1%) i/s - 872.000 in 10.024951s
parse & render: 26.139 (± 0.0%) i/s - 262.000 in 10.023365s
我已经尽力将基准工作负载与参考实现匹配,以便我们可以直接比较结果。该工作负载旨在代表Shopify的使用案例,虽然我不会对基准测试用例设计以来他们的使用已经发生微妙变化感到惊讶。
贡献
请参阅Python Liquid的贡献。
项目详情
下载文件
下载适用于您的平台的文件。如果您不确定选择哪一个,请了解更多关于安装包的信息。
源代码分发
python_liquid-1.12.1.tar.gz (124.6 KB 查看哈希值)
构建发行版
python_liquid-1.12.1-py3-none-any.whl (206.6 kB 查看哈希值)
关闭
python_liquid-1.12.1.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 7367e979125859fb4116f360f224a89a52ecb455fb26843c43e4d800b389d325 |
|
MD5 | feb56b93edc469d50ec4a4f5a30aaf89 |
|
BLAKE2b-256 | 59b4c4e39470edf507056333cd688a36bb7fbdb17090105d9f454ecf6ff09845 |
关闭
python_liquid-1.12.1-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 2224312944be16c1a44406398eb8a07c7e57398d5c0ef15ff950946dbefe7c33 |
|
MD5 | 174b1128110cdc3a3017c41c7bd0c683 |
|
BLAKE2b-256 | 2c6ebfd01926e28f6cf355a7a8460271ba135013870f5857b06f35dbf65ab237 |