Skip to content

sift_client.util.cel_utils

CEL (Common Expression Language) utilities for generating CEL expressions.

This module provides helper functions to generate CEL expressions for building filters commonly used in Sift.

FUNCTION DESCRIPTION
and_

Generates a CEL expression that joins all clauses with an AND operator.

contains

Generates a CEL expression that checks whether a string field contains a given value.

equals

Generates a CEL expression that checks for equality.

equals_all

Generates a CEL expression that checks for equality of all key-value pairs.

equals_any

Generates a CEL expression that checks for equality of any key-value pairs.

equals_double

Generates a CEL expression that checks for equality with a double value.

equals_null

Generates a CEL expression that checks for equality with null.

greater_than

Generates a CEL expression that checks whether a numeric or datetime field is greater than a given value.

in_

Generates a CEL expression that checks for field membership in vals.

less_than

Generates a CEL expression that checks whether a numeric or datetime field is less than a given value.

match

Generates a CEL expression that checks for a match on the specified field.

not_

Generates a CEL expression that negates the given clause.

or_

Generates a CEL expression that joins all clauses with an OR operator.

parens

Wraps the given expression in parentheses.

and_

and_(*clauses: str) -> str

Generates a CEL expression that joins all clauses with an AND operator.

PARAMETER DESCRIPTION
*clauses

Variable number of CEL expression strings

TYPE: str DEFAULT: ()

RETURNS DESCRIPTION
str

A CEL expression string with all clauses joined by AND

contains

contains(field: str, value: str) -> str

Generates a CEL expression that checks whether a string field contains a given value.

PARAMETER DESCRIPTION
field

The field name

TYPE: str

value

The substring to check for

TYPE: str

RETURNS DESCRIPTION
str

A CEL expression string

equals

equals(key: str, value: Any) -> str

Generates a CEL expression that checks for equality.

PARAMETER DESCRIPTION
key

The field name

TYPE: str

value

The value to compare against

TYPE: Any

RETURNS DESCRIPTION
str

A CEL expression string

equals_all

equals_all(values: dict[str, Any]) -> str

Generates a CEL expression that checks for equality of all key-value pairs.

PARAMETER DESCRIPTION
values

Dictionary of field names and values to check for equality

TYPE: dict[str, Any]

RETURNS DESCRIPTION
str

A CEL expression string with all equality checks joined by AND

equals_any

equals_any(values: dict[str, Any]) -> str

Generates a CEL expression that checks for equality of any key-value pairs.

PARAMETER DESCRIPTION
values

Dictionary of field names and values to check for equality

TYPE: dict[str, Any]

RETURNS DESCRIPTION
str

A CEL expression string with all equality checks joined by OR

equals_double

equals_double(key: str, value: Any) -> str

Generates a CEL expression that checks for equality with a double value.

PARAMETER DESCRIPTION
key

The field name

TYPE: str

value

The value to compare against as a double

TYPE: Any

RETURNS DESCRIPTION
str

A CEL expression string

equals_null

equals_null(key: str) -> str

Generates a CEL expression that checks for equality with null.

PARAMETER DESCRIPTION
key

The field name

TYPE: str

RETURNS DESCRIPTION
str

A CEL expression string

greater_than

greater_than(
    field: str, value: int | float | datetime
) -> str

Generates a CEL expression that checks whether a numeric or datetime field is greater than a given value.

PARAMETER DESCRIPTION
field

The field name

TYPE: str

value

The value to compare against

TYPE: int | float | datetime

RETURNS DESCRIPTION
str

A CEL expression string

in_

in_(field: str, vals: list[str]) -> str

Generates a CEL expression that checks for field membership in vals.

PARAMETER DESCRIPTION
field

The field name to check

TYPE: str

vals

List of string values to check membership against

TYPE: list[str]

RETURNS DESCRIPTION
str

A CEL expression string or empty string if vals is empty

less_than

less_than(field: str, value: int | float | datetime) -> str

Generates a CEL expression that checks whether a numeric or datetime field is less than a given value.

PARAMETER DESCRIPTION
field

The field name

TYPE: str

value

The value to compare against

TYPE: int | float | datetime

RETURNS DESCRIPTION
str

A CEL expression string

match

match(field: str, query: str | Pattern) -> str

Generates a CEL expression that checks for a match on the specified field.

PARAMETER DESCRIPTION
field

The field name

TYPE: str

query

The regex pattern to match against

TYPE: str | Pattern

RETURNS DESCRIPTION
str

A CEL expression string

not_

not_(clause: str) -> str

Generates a CEL expression that negates the given clause.

PARAMETER DESCRIPTION
clause

The CEL expression to negate

TYPE: str

RETURNS DESCRIPTION
str

A negated CEL expression string

or_

or_(*clauses: str) -> str

Generates a CEL expression that joins all clauses with an OR operator.

PARAMETER DESCRIPTION
*clauses

Variable number of CEL expression strings

TYPE: str DEFAULT: ()

RETURNS DESCRIPTION
str

A CEL expression string with all clauses joined by OR

parens

parens(expr: str) -> str

Wraps the given expression in parentheses.

PARAMETER DESCRIPTION
expr

The expression to wrap in parentheses

TYPE: str

RETURNS DESCRIPTION
str

A CEL expression string with parentheses