
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
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 Python Liquid using Pipenv:
$ pipenv install -u python-liquid
Or pip:
$ pip install python-liquid
Or from conda-forge:
$ conda install -c conda-forge python-liquid
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"
.
from liquid 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 BoundTemplate
instance with a render()
method.
from liquid import parse
template = parse("Hello, {{ you }}!")
print(template.render(you="World")) # Hello, World!
print(template.render(you="Liquid")) # Hello, Liquid!
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 liquid import CachingFileSystemLoader
from liquid import Environment
env = 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.
# ... 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.
Please see Contributing to Python Liquid.
FAQs
A Python engine for the Liquid template language.
We found that python-liquid demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.