Skip to main content

A Python engine for the Liquid template language.

Project description

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.

PyPi - Version conda-forge Python versions
Tests Coverage
PyPI - Downloads
License


Table of Contents

Install

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

Links

Related Projects

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".

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!

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 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.

Contributing

Please see Contributing to Python Liquid.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_liquid-2.0.2.tar.gz (91.6 kB view details)

Uploaded Source

Built Distribution

python_liquid-2.0.2-py3-none-any.whl (136.3 kB view details)

Uploaded Python 3

File details

Details for the file python_liquid-2.0.2.tar.gz.

File metadata

  • Download URL: python_liquid-2.0.2.tar.gz
  • Upload date:
  • Size: 91.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.10

File hashes

Hashes for python_liquid-2.0.2.tar.gz
Algorithm Hash digest
SHA256 3b10c3716829778284e545afa968252bc51bc67ad8d13b3d93975d3affa92e2e
MD5 2a543b221fdc097dc826c5a8a14c1b31
BLAKE2b-256 d32945ea9b5b22394aaea4d981960531c1de8cc46b9f4f85ddef3ff180740a8d

See more details on using hashes here.

File details

Details for the file python_liquid-2.0.2-py3-none-any.whl.

File metadata

  • Download URL: python_liquid-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 136.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.10

File hashes

Hashes for python_liquid-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 599ac3f0fcfc77c914447a0c53f87a55b537ffe5d0169f2fffdc8216577161c0
MD5 50251e23a32cbf77f923f5cf10738361
BLAKE2b-256 9a644e7d316c3ebaaae8a5f6fdbfa5067285f66bceed66ef002b21ac3033049d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page