ds_common_placeholder_py_lib.functions

File: functions/__init__.py Region: ds-common-placeholder-py-lib

Description

The function registry (contract §5). Adding a function is a contract change: registry, vectors, and version bump together.

Submodules

Attributes

FUNCTIONS

secret marks the functions that read secrets.

Classes

Param

A function parameter. default is None for a required one;

FunctionSpec

One registry entry.

Functions

service_function(name, fn) → FunctionSpec

A function a service adds to its context: called with each

Package Contents

class ds_common_placeholder_py_lib.functions.Param[source]

A function parameter. default is None for a required one; check validates a string value and raises argument.

name: str
default: Any = None
check: collections.abc.Callable[[str], object] | None = None
class ds_common_placeholder_py_lib.functions.FunctionSpec[source]

One registry entry.

name: str
impl: collections.abc.Callable[..., Any]

Called with the argument list; a secret function, which needs the context’s tenant and records what it reads, with the context first.

params: tuple[Param, ...] = ()
variadic: bool = False
secret: bool = False
lazy: bool = False

impl gets one zero-argument callable per argument instead of its value; calling it reads the value, or raises MissingValue.

min_variadic: int = 1
raw: bool = False

any JSON value, or what a provider returned (a DataFrame), None for null or blank. Its result is converted to plain JSON.

Type:

impl gets each argument’s value as it is

call(ctx: ds_common_placeholder_py_lib.context.Context, args: list[Any]) → Any[source]

Run the function: built-ins depend only on args; the secret functions also get ctx.

property min_args: int

Smallest accepted argument count.

property max_args: int | None

Largest accepted argument count, None for no limit.

ds_common_placeholder_py_lib.functions.FUNCTIONS: collections.abc.Mapping[str, FunctionSpec]

secret marks the functions that read secrets.

Type:

Function name to spec

ds_common_placeholder_py_lib.functions.service_function(name: str, fn: collections.abc.Callable[..., Any]) → FunctionSpec[source]

A function a service adds to its context: called with each argument’s value, positionally, as a raw function. Its signature gives the argument counts it accepts.

Raises:
  • ValueError – If name is not a function name, is a built-in one, or fn has a required keyword-only parameter.

  • TypeError – If fn is not callable.