Skip to content

Filter helpers

liquid2.filter.bool_arg

bool_arg(value: object) -> bool

Return True if value is liquid truthy, or False otherwise.

liquid2.filter.decimal_arg

decimal_arg(
    val: Any, default: int | Decimal | None = None
) -> int | Decimal

Return val as an int or decimal, or default is casting fails.

liquid2.filter.int_arg

int_arg(val: Any, default: int | None = None) -> int

Return val as an int, or default if val can't be cast to an int.

liquid2.filter.mapping_arg

mapping_arg(value: object) -> Mapping[Any, Any]

Make sure value is a mapping type.

RAISES DESCRIPTION
LiquidTypeError

If value can't be coerced to a mapping.

liquid2.filter.math_filter

math_filter(
    _filter: Callable[..., Any]
) -> Callable[..., Any]

Raise a LiquidTypeError if the filter value can not be cast to a number.

liquid2.filter.num_arg

num_arg(
    val: Any, default: float | int | None = None
) -> float | int

Return val as an int or float, or default if casting fails.

liquid2.filter.sequence_filter

sequence_filter(
    _filter: Callable[..., Any]
) -> Callable[..., Any]

Coerce the left value to sequence.

This is intended to mimic the semantics of the reference implementation's InputIterator class.

liquid2.filter.string_filter

string_filter(
    _filter: Callable[..., Any]
) -> Callable[..., Any]

A filter function decorator that converts the first argument to a string.

liquid2.filter.with_context

with_context(
    _filter: Callable[..., Any]
) -> Callable[..., Any]

Ensure the wrapped callable is passed a context keyword argument.

liquid2.filter.with_environment

with_environment(
    _filter: Callable[..., Any]
) -> Callable[..., Any]

Ensure the wrapped callable is passed an environment keyword argument.