Skip to content

sift_client.resources.user_defined_functions

CLASS DESCRIPTION
UserDefinedFunctionVersionsAPIAsync

High-level API for a function's version history.

UserDefinedFunctionsAPIAsync

High-level API for interacting with user-defined functions.

UserDefinedFunctionVersionsAPIAsync

UserDefinedFunctionVersionsAPIAsync(
    sift_client: SiftClient,
)

Bases: ResourceBase

High-level API for a function's version history.

Every save produces a new version. Reachable as client.user_defined_functions.versions.

Initialize the UserDefinedFunctionVersionsAPI.

PARAMETER DESCRIPTION
sift_client

The Sift client to use.

TYPE: SiftClient

METHOD DESCRIPTION
get

Get one version.

batch_get

Get many versions in one call.

list_

List a function's versions.

ATTRIBUTE DESCRIPTION
client

TYPE: SiftClient

grpc_client

TYPE: GrpcClient

rest_client

TYPE: RestClient

client property

client: SiftClient

grpc_client property

grpc_client: GrpcClient

rest_client property

rest_client: RestClient

get async

Get one version.

PARAMETER DESCRIPTION
version

The UserDefinedFunctionVersion or version ID.

TYPE: str | UserDefinedFunctionVersion

RETURNS DESCRIPTION
UserDefinedFunctionVersion

The UserDefinedFunctionVersion.

batch_get async

batch_get(
    *,
    versions: list[str] | list[UserDefinedFunctionVersion],
) -> list[UserDefinedFunctionVersion]

Get many versions in one call.

PARAMETER DESCRIPTION
versions

The UserDefinedFunctionVersions or version IDs.

TYPE: list[str] | list[UserDefinedFunctionVersion]

RETURNS DESCRIPTION
list[UserDefinedFunctionVersion]

The UserDefinedFunctionVersions.

list_ async

list_(
    *,
    user_defined_function: str
    | UserDefinedFunction
    | None = None,
    name: str | None = None,
    version: int | None = None,
    include_archived: bool = False,
    filter_query: str | None = None,
    order_by: str | None = None,
    limit: int | None = None,
    page_size: int | None = None,
) -> list[UserDefinedFunctionVersion]

List a function's versions.

PARAMETER DESCRIPTION
user_defined_function

The UserDefinedFunction or function ID whose versions to list.

TYPE: str | UserDefinedFunction | None DEFAULT: None

name

The function name, as an alternative to user_defined_function.

TYPE: str | None DEFAULT: None

version

Filter to a single version number.

TYPE: int | None DEFAULT: None

include_archived

If True, include archived versions in results.

TYPE: bool DEFAULT: False

filter_query

Explicit CEL query to filter versions.

TYPE: str | None DEFAULT: None

order_by

Field and direction to order results by.

TYPE: str | None DEFAULT: None

limit

Maximum number of versions to return. If None, returns all matches.

TYPE: int | None DEFAULT: None

page_size

Number of results to fetch per request.

TYPE: int | None DEFAULT: None

RETURNS DESCRIPTION
list[UserDefinedFunctionVersion]

A list of UserDefinedFunctionVersion objects in the service's order, which is

list[UserDefinedFunctionVersion]

by name unless order_by says otherwise. Every version shares the function's

list[UserDefinedFunctionVersion]

name, so pass order_by="version desc" for newest first.

UserDefinedFunctionsAPIAsync

UserDefinedFunctionsAPIAsync(sift_client: SiftClient)

Bases: ResourceBase

High-level API for interacting with user-defined functions.

A user-defined function is a named expression that calculated channels and rules can call. Every save produces a new version.

Initialize the UserDefinedFunctionsAPI.

PARAMETER DESCRIPTION
sift_client

The Sift client to use.

TYPE: SiftClient

METHOD DESCRIPTION
get

Get a UserDefinedFunction.

list_

List user-defined functions.

find

Find one function. Takes the same arguments as list_.

create

Create a new function.

update

Update a function.

validate_expression

Check an expression without saving it.

get_where_used

Get what uses a function.

archive

Archive a function.

unarchive

Unarchive a function.

ATTRIBUTE DESCRIPTION
versions

client

TYPE: SiftClient

grpc_client

TYPE: GrpcClient

rest_client

TYPE: RestClient

versions instance-attribute

versions = UserDefinedFunctionVersionsAPIAsync(sift_client)

client property

client: SiftClient

grpc_client property

grpc_client: GrpcClient

rest_client property

rest_client: RestClient

get async

get(
    *, user_defined_function_id: str
) -> UserDefinedFunction

Get a UserDefinedFunction.

PARAMETER DESCRIPTION
user_defined_function_id

The ID of the function.

TYPE: str

RETURNS DESCRIPTION
UserDefinedFunction

The UserDefinedFunction.

list_ async

list_(
    *,
    name: str | None = None,
    name_contains: str | None = None,
    name_regex: str | Pattern | None = None,
    user_defined_function_ids: list[str]
    | list[UserDefinedFunction]
    | None = None,
    include_archived: bool = False,
    filter_query: str | None = None,
    order_by: str | None = None,
    limit: int | None = None,
    page_size: int | None = None,
) -> list[UserDefinedFunction]

List user-defined functions.

PARAMETER DESCRIPTION
name

Exact name of the function.

TYPE: str | None DEFAULT: None

name_contains

Partial name of the function.

TYPE: str | None DEFAULT: None

name_regex

Regular expression to filter functions by name.

TYPE: str | Pattern | None DEFAULT: None

user_defined_function_ids

Filter to these UserDefinedFunctions or function IDs.

TYPE: list[str] | list[UserDefinedFunction] | None DEFAULT: None

include_archived

If True, include archived functions in results.

TYPE: bool DEFAULT: False

filter_query

Explicit CEL query to filter functions.

TYPE: str | None DEFAULT: None

order_by

Field and direction to order results by.

TYPE: str | None DEFAULT: None

limit

Maximum number of functions to return. If None, returns all matches.

TYPE: int | None DEFAULT: None

page_size

Number of results to fetch per request.

TYPE: int | None DEFAULT: None

RETURNS DESCRIPTION
list[UserDefinedFunction]

A list of UserDefinedFunction objects that match the filter criteria.

find async

find(**kwargs) -> UserDefinedFunction | None

Find one function. Takes the same arguments as list_.

Raises if more than one matches.

PARAMETER DESCRIPTION
**kwargs

Keyword arguments to pass to list_.

DEFAULT: {}

RETURNS DESCRIPTION
UserDefinedFunction | None

The UserDefinedFunction found or None.

create async

create(
    create: UserDefinedFunctionCreate | dict,
) -> UserDefinedFunction

Create a new function.

PARAMETER DESCRIPTION
create

The function definition.

TYPE: UserDefinedFunctionCreate | dict

RETURNS DESCRIPTION
UserDefinedFunction

The created UserDefinedFunction.

update async

update(
    user_defined_function: str | UserDefinedFunction,
    update: UserDefinedFunctionUpdate | dict,
    change_notes: str | None = None,
) -> UserDefinedFunction

Update a function.

Changes to the expression, inputs, description, or metadata create a new version.

PARAMETER DESCRIPTION
user_defined_function

The UserDefinedFunction or function ID to update.

TYPE: str | UserDefinedFunction

update

Updates to apply to the function.

TYPE: UserDefinedFunctionUpdate | dict

change_notes

A note to attach to the new version. The server treats an empty note as a change, so the current version's note carries over when omitted.

TYPE: str | None DEFAULT: None

RETURNS DESCRIPTION
UserDefinedFunction

The updated UserDefinedFunction.

validate_expression async

validate_expression(
    expression: str, function_inputs: list[FunctionInput]
) -> UserDefinedFunctionValidation

Check an expression without saving it.

PARAMETER DESCRIPTION
expression

The expression to check.

TYPE: str

function_inputs

The inputs the expression refers to. The server rejects an empty list.

TYPE: list[FunctionInput]

RETURNS DESCRIPTION
UserDefinedFunctionValidation

Whether the expression compiles, and its output type or error.

get_where_used async

get_where_used(
    user_defined_function: str
    | UserDefinedFunction
    | None = None,
    *,
    version: str | UserDefinedFunctionVersion | None = None,
) -> FunctionUsage

Get what uses a function.

Check this before changing inputs or the output type. The server refuses those changes once a function is in use.

Each result set is capped at 1000. The service pages them separately but accepts no page token, so the rest cannot be fetched; FunctionUsage.truncated says when that happened.

PARAMETER DESCRIPTION
user_defined_function

The UserDefinedFunction or function ID.

TYPE: str | UserDefinedFunction | None DEFAULT: None

version

A specific UserDefinedFunctionVersion or version ID, instead of the function as a whole.

TYPE: str | UserDefinedFunctionVersion | None DEFAULT: None

RETURNS DESCRIPTION
FunctionUsage

The functions, calculated channels, and rules that use it.

RAISES DESCRIPTION
ValueError

If neither or both are provided.

archive async

archive(
    user_defined_function: str | UserDefinedFunction,
) -> UserDefinedFunction

Archive a function.

PARAMETER DESCRIPTION
user_defined_function

The UserDefinedFunction or function ID to archive.

TYPE: str | UserDefinedFunction

RETURNS DESCRIPTION
UserDefinedFunction

The archived UserDefinedFunction.

unarchive async

unarchive(
    user_defined_function: str | UserDefinedFunction,
) -> UserDefinedFunction

Unarchive a function.

PARAMETER DESCRIPTION
user_defined_function

The UserDefinedFunction or function ID to unarchive.

TYPE: str | UserDefinedFunction

RETURNS DESCRIPTION
UserDefinedFunction

The unarchived UserDefinedFunction.