Development Status
- 5 - Production/Stable
Intended Audience
- Developers
License
- OSI Approved :: MIT License
Programming Language
- Python
- Python :: 3.12
- Python :: 3.13
- Python :: 3.14
- Python :: 3.15
- Python :: Implementation :: CPython
- Python :: Implementation :: PyPy
Python Liquid
Python Liquid is a Python engine for Liquid, the safe, customer-facing template language.
We follow Shopify/Liquid closely and test against the Golden Liquid test suite.
Table of Contents
Install
Install python-liquid from PyPi using your favorite package manager.
pip
pip install python-liquid
uv
uv add python-liquid
pipenv
pipenv install -u python-liquid
conda
conda install -c conda-forge python-liquid
Links
- Documentation: https://jg-rp.github.io/liquid/
- Documentation for Python Liquid version 1.x: https://jg-rp.github.io/python-liquid-docs-archive/
- Documentation for Python Liquid version 2.x: https://github.com/jg-rp/liquid/blob/v2.3.6/docs/index.md
- Change Log: https://github.com/jg-rp/liquid/blob/main/CHANGES.md
- PyPi: https://pypi.org/project/python-liquid/
- Source Code: https://github.com/jg-rp/liquid
- Issue Tracker: https://github.com/jg-rp/liquid/issues
Related Projects
- Python Liquid2: A new Python engine for Liquid with extra features.
- Ruby Liquid2: Liquid2 templates for Ruby.
- Micro Liquid: A stripped-down Liquid-like template engine for Python. You can think of it as a non-evaluating alternative to Python's f-strings or t-strings.
- LiquidScript: A JavaScript engine for Liquid with a similar high-level API to Python Liquid.
Quick Start
render()
Use the package-level liquid.render() function to render a template with Liquid's default configuration. The first argument is template source code and the second is a dictionary of template variables.
import liquid
print(liquid.render("Hello, {{ you }}!", {"you": "World"})) # Hello, World!
parse()
Use liquid.parse() to get an instance of liquid.Template, which can be rendered multiple times with different data.
from liquid import parse
template = parse("Hello, {{ you }}!")
print(template.render(you="World")) # Hello, World!
print(template.render(you="Liquid")) # Hello, Liquid!
Configure
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!")
See docs.
Contributing
Please see Contributing to Python Liquid.