Skip to content

Python Liquid

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

Info

See https://jg-rp.github.io/liquid/ for guides, tag and filter references and extra, non-standard plugins.

Install

Install Python Liquid using Pipenv:

$ pipenv install -u python-liquid

Or pip:

$ pip install python-liquid

Or from conda-forge:

$ conda install -c conda-forge python-liquid

Quick Start

Render a template string by creating a Template and calling its render() method.

from liquid import Template

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

Keyword arguments passed to render() are available as variables for templates to use in Liquid expressions.

from liquid import Template

template = Template(
    "{% for person in people %}"
    "Hello, {{ person.name }}!\n"
    "{% endfor %}"
)

data = {
    "people": [
        {"name": "John"},
        {"name": "Sally"},
    ]
}

print(template.render(**data))
# Hello, John!
# Hello, Sally!

What's next?

Learn how to configure a Liquid environment and load templates from a file system or database.