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.
pip install python-liquidVerified import paths — ran on the pinned version, not inferred.
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.
Refer to the archived documentation for 1.x and the current documentation for 2.x to identify specific API changes and migration paths. Thoroughly test your application after upgrading.
Initialize a single `Environment` instance for your application and use its `get_template()` or `from_string()` methods to load and render templates.
Utilize whitespace control characters (`-` within `{%` or `}}` tags, e.g., `{%-` or `-%}`) to strip leading or trailing whitespace around tags and output, as described in the Liquid syntax documentation.Keep business logic in your Python application code. Use Liquid templates solely for presentation and data display. Pre-process data in Python before passing it to the Liquid template for rendering.