Skip to main content

A Python engine for the Liquid template language.

Project description

A Python implementation of Liquid, the safe, customer-facing template language for flexible web apps.

Version conda-forge Tests Coverage License Python versions PyPy versions
from liquid import Template

template = Template("Hello, {{ you }}!")
print(template.render(you="World"))  # "Hello, World!"
print(template.render(you="Liquid"))  # "Hello, Liquid!"

Installing

Install Python Liquid using Pipenv:

$ pipenv install python-liquid

Or pip:

$ python -m pip install -U python-liquid

Or from conda-forge:

$ conda install -c conda-forge python-liquid

Compatibility

We strive to be 100% compatible with the reference implementation of Liquid, written in Ruby. That is, given an equivalent render context, a template rendered with Python Liquid should produce the same output as when rendered with Ruby Liquid.

See the known issues page for details of known incompatibilities between Python Liquid and Ruby Liquid, and please help by raising an issue if you notice an incompatibility.

Benchmark

You can run the benchmark using make benchmark (or python -O performance.py if you don’t have make) from the root of the source tree. On my ropey desktop computer with a Ryzen 5 1500X and Python 3.11.0, we get the following results.

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)

And PyPy3.7 gives us a decent increase in performance.

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)

On the same machine, running rake benchmark:run from the root of the reference implementation source tree gives us these results.

/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

I’ve tried to match the benchmark workload to that of the reference implementation, so that we might compare results directly. The workload is meant to be representative of Shopify’s use case, although I wouldn’t be surprised if their usage has changed subtly since the benchmark fixture was designed.

Contributing

Please see Contributing to Python Liquid.

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

python-liquid-1.4.6.tar.gz (795.0 kB view details)

Uploaded Source

Built Distribution

python_liquid-1.4.6-py3-none-any.whl (161.6 kB view details)

Uploaded Python 3

File details

Details for the file python-liquid-1.4.6.tar.gz.

File metadata

  • Download URL: python-liquid-1.4.6.tar.gz
  • Upload date:
  • Size: 795.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for python-liquid-1.4.6.tar.gz
Algorithm Hash digest
SHA256 868f0c47e8e1d7c56457b3bb3332b686fc0125f3810d144cb88e689282a5e1c1
MD5 8ede9032221533c5b350ac2acb2ce203
BLAKE2b-256 2b90675d766c45bbb10c74a7434c44f4d45e6dcea8ffdf6fc036d64560c409d1

See more details on using hashes here.

File details

Details for the file python_liquid-1.4.6-py3-none-any.whl.

File metadata

File hashes

Hashes for python_liquid-1.4.6-py3-none-any.whl
Algorithm Hash digest
SHA256 65ec0c15f300b45ff1000c4dd66107244e1356d35177f5361346f1c02113be40
MD5 7305ae5c5e5e25a0ec735edc5f7fba95
BLAKE2b-256 f49f095d1244750d9dadd2414eaf6d3e301232f3a53ae85a5bf1016232626b63

See more details on using hashes here.

Supported by

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