Python Liquid2
Liquid templates for Python, with some extra features.
Table of Contents
Install
Install Python Liquid2 from PyPi using pip:
python -m pip install python-liquid2
Or Pipenv:
pipenv install python-liquid2
Or Poetry:
poetry add python-liquid2
Links
- Documentation: https://jg-rp.github.io/python-liquid2/
- Change Log: https://github.com/jg-rp/python-liquid2/blob/main/CHANGES.md
- PyPi: https://pypi.org/project/python-liquid2/
- Source Code: https://github.com/jg-rp/python-liquid2
- Issue Tracker: https://github.com/jg-rp/python-liquid2/issues
Quick start
render()
Here's a very simple example that 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".
from liquid2 import render
print(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 Template instance with a render() method.
from liquid2 import parse
template = 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.
from liquid2 import CachingFileSystemLoader
from liquid2 import Environment
env = Environment(
auto_escape=True,
loader=CachingFileSystemLoader("./templates"),
)
Then, using env.from_string() or env.get_template(), we can create a Template from a string or read from the file system, respectively.
# ... continued from above
template = env.from_string("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.
Metadata
Release files for python-liquid2 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| python_liquid2-0.4.0.tar.gz | 88.0 kB | Without provenance | Details for python_liquid2-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_liquid2-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for python_liquid2-0.4.0-py3-none-any.whl |
Total release size: 217.9 kB
Release files / python_liquid2-0.4.0.tar.gz
| Download URL | python_liquid2-0.4.0.tar.gz |
|---|---|
| Size | 88.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2d9499ab7e7ca1ec10a1c2b2ff2a7a292b9e1eda3ff7ffe8c409ce2a8675e9ab
|
|
BLAKE2b-256 checksum How to use checksums |
9a4811a415c56ac4410ef1c69559eaf5b2e696717252aaebd55beb33582f3ff5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|
Release files / python_liquid2-0.4.0-py3-none-any.whl
| Download URL | python_liquid2-0.4.0-py3-none-any.whl |
|---|---|
| Size | 130.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a5ab10e12ebf80c1dc35906d41f7180587c7553a308370d06a7e242d7c41f5f5
|
|
BLAKE2b-256 checksum How to use checksums |
f482eab55b9b0dee18144619f9383db25a5c9916d0aaa5681a5c07d92e307196
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|
Security for python-liquid2 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.