Skip to content

Convenience functions

liquid.parse

parse(source: str) -> BoundTemplate

Parse template source text using the default environment.

liquid.render

render(source: str, **data: object) -> str

Parse and render source text using the default environment.

liquid.render_async async

render_async(source: str, **data: object) -> str

Parse and render source text using the default environment.

liquid.extract_liquid

extract_liquid(
    fileobj: TextIO,
    keywords: list[str],
    comment_tags: Optional[list[str]] = None,
    options: Optional[dict[object, object]] = None,
) -> Iterator[MessageTuple]

A babel compatible translation message extraction method for Liquid templates.

See https://babel.pocoo.org/en/latest/messages.html

Keywords are the names of Liquid filters or tags operating on translatable strings. For a filter to contribute to message extraction, it must also appear as a child of a FilteredExpression and be a TranslatableFilter. Similarly, tags must produce a node that is a TranslatableTag.

Where a Liquid comment contains a prefix in comment_tags, the comment will be attached to the translatable filter or tag immediately following the comment. Python Liquid's non-standard shorthand comments are not supported.

Options are arguments passed to the liquid.Template constructor with the contents of fileobj as the template's source. Use extract_from_template to extract messages from an existing template bound to an existing environment.