https://github.com/jg-rp/liquid
A Python engine for the Liquid template language.
https://github.com/jg-rp/liquid
liquid liquid-templating-engine pypy3 python template-engine templates
Last synced: 3 months ago
JSON representation
A Python engine for the Liquid template language.
- Host: GitHub
- URL: https://github.com/jg-rp/liquid
- Owner: jg-rp
- License: mit
- Created: 2020-10-15T14:25:27.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-04-09T14:26:00.000Z (3 months ago)
- Last Synced: 2025-04-12T11:55:11.070Z (3 months ago)
- Topics: liquid, liquid-templating-engine, pypy3, python, template-engine, templates
- Language: Python
- Homepage: https://jg-rp.github.io/liquid/
- Size: 16.9 MB
- Stars: 71
- Watchers: 2
- Forks: 11
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- Contributing: contributing.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
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)
- [Links](#links)
- [Related Projects](#related-projects)
- [Quick Start](#example)
- [Contributing](#contributing)## Install
Install Python Liquid using [Pipenv](https://pipenv.pypa.io/en/latest/):
```shell
$ pipenv install -u python-liquid
```Or [pip](https://pip.pypa.io/en/stable/getting-started/):
```shell
$ pip install python-liquid
```Or from [conda-forge](https://anaconda.org/conda-forge/python-liquid):
```shell
$ 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/
- 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](https://github.com/jg-rp/python-liquid2): A new Python engine for Liquid with [extra features](https://jg-rp.github.io/python-liquid2/migration/#new-features).
- [LiquidScript](https://github.com/jg-rp/liquidscript): A JavaScript engine for Liquid with a similar high-level API to Python Liquid.## Quick Start
### `render()`
This example renders a template from a string of text with the package-level `render()` function. The template has just one placeholder variable `you`, which we've given the value `"World"`.
```python
from liquid import renderprint(render("Hello, {{ you }}!", you="World"))
# Hello, World!
```### `parse()`
Often you'll want to render the same template several times with different variables. We can parse source text without immediately rendering it using the `parse()` function. `parse()` returns a `BoundTemplate` instance with a `render()` method.
```python
from liquid import parsetemplate = parse("Hello, {{ you }}!")
print(template.render(you="World")) # Hello, World!
print(template.render(you="Liquid")) # Hello, Liquid!
```### Configure
Both `parse()` and `render()` are convenience functions that use the default Liquid environment. For all but the simplest cases, you'll want to configure an instance of `Environment`, then load and render templates from that.
```python
from liquid import CachingFileSystemLoader
from liquid import Environmentenv = Environment(
autoescape=True,
loader=CachingFileSystemLoader("./templates"),
)
```Then, using `env.parse()` or `env.get_template()`, we can create a `BoundTemplate` from a string or read from the file system, respectively.
```python
# ... continued from above
template = env.parse("Hello, {{ you }}!")
print(template.render(you="World")) # Hello, World!# Try to load "./templates/index.html"
another_template = env.get_template("index.html")
data = {"some": {"thing": [1, 2, 3]}}
result = another_template.render(**data)
```Unless you happen to have a relative folder called `templates` with a file called `index.html` within it, we would expect a `TemplateNotFoundError` to be raised when running the example above.
## Contributing
Please see [Contributing to Python Liquid](https://github.com/jg-rp/liquid/blob/main/contributing.md).