Python Liquid¶
Python Liquid is a Python engine for Liquid, the safe, customer-facing template language. We follow Shopify/liquid closely and test against Shopify/liquid-spec.
Note
This is the documentation for Python Liquid version 3 (GitHub). Archived documentation for versions 1 and 2 can be found here and here, respectively.
Install¶
Install python-liquid from PyPI using your favorite package manager.
pip
python -m pip install python-liquid
uv
uv add python-liquid
pipenv
pipenv install -u python-liquid
Quick start¶
Use the package-level liquid.render() function to render a template with Liquid’s
default configuration.
import liquid
print(liquid.render("Hello, {{ you }}!", {"you": "World"})) # Hello, World!
And liquid.parse() to get an instance of liquid.Template, which can be
rendered multiple times with different data.
import liquid
template = liquid.parse("Hello, {{ you }}!")
print(template.render({"you": "World"})) # Hello, World!
print(template.render({"you": "Liquid"})) # Hello, Liquid!
You’ll need to create an instance of liquid.Environment to configure Liquid,
then load and render templates from that.
from liquid import Environment, CachingFileSystemLoader
env = Environment(
autoescape=True,
loader=CachingFileSystemLoader("./templates")
)
template = env.get_template("index.liquid")
another_template = env.parse("{% render 'greeting' %}, World!")