Python Liquid

2.1.0 · active · verified Sat Apr 11

Python Liquid is a Python engine for Liquid, the safe, customer-facing template language, currently at version 2.1.0. It closely follows Shopify/Liquid's design and test suite, providing a robust and secure templating solution for web applications. While there isn't a fixed release cadence, the project is actively maintained with regular updates.

Warnings

Install

Imports

Quickstart

The simplest way to render a template string is using the package-level `render()` function. For applications requiring configuration, template loading from files, or better performance, it's recommended to configure an `Environment` instance. This example demonstrates using `Environment` with a `FileSystemLoader` to render a template from a file, passing variables and accessing globals.

from liquid import Environment, FileSystemLoader
import os

# For a simple template string, use render() or parse():
# from liquid import render
# print(render("Hello, {{ you }}!", you="World"))

# For more complex applications, an Environment is recommended.
# This example assumes a 'templates' directory with 'index.liquid'.

# Create a dummy templates directory and file for demonstration
os.makedirs("templates", exist_ok=True)
with open("templates/index.liquid", "w") as f:
    f.write("Hello, {{ name }}! From {{ app_name }}. Today is {{ date | date: '%Y-%m-%d' }}.")

env = Environment(
    loader=FileSystemLoader("templates/"),
    globals={
        "app_name": os.environ.get('LIQUID_APP_NAME', 'Default App') # Example with env var
    }
)

template = env.get_template("index.liquid")
output = template.render(name="Liquid User", date="2026-04-11")
print(output)

# Clean up dummy files/directory
os.remove("templates/index.liquid")
os.rmdir("templates")

view raw JSON →