Skip to content

Ops

API for implementing LynxKite operations.

LongStr module-attribute ¤

LongStr = Annotated[str, {'format': 'textarea'}]

LongStr is a string type for parameters that will be displayed as a multiline text area in the UI.

Op ¤

Bases: BaseConfig

convert_params ¤

convert_params(params: dict[str, Any])

Returns the parameters converted to the expected type.

get_input ¤

get_input(name: str)

Returns the input with the given name.

get_output ¤

get_output(name: str)

Returns the output with the given name.

Parameter ¤

Bases: BaseConfig

Defines a parameter for an operation.

ParameterGroup ¤

Bases: BaseConfig

Defines a group of parameters for an operation.

Position ¤

Bases: str, Enum

Defines the position of an input or output in the UI.

Result dataclass ¤

Represents the result of an operation.

The output attribute is what will be used as input for other operations. The display attribute is used to send data to display on the UI. The value has to be JSON-serializable. input_metadata is a list of JSON objects describing each input.

get_optional_type ¤

get_optional_type(type)

For a type like int | None, returns int. Returns None otherwise.

input_position ¤

input_position(**positions)

Decorator for specifying unusual positions for the inputs.

Example usage:

@input_position(a="bottom", b="bottom")
@op("test", "maybe add")
def maybe_add(a: list[int], b: list[int] | None = None):
    return [a + b for a, b in zip(a, b)] if b else a

load_user_scripts ¤

load_user_scripts(workspace: str)

Reloads the *.py in the workspace's directory and higher-level directories.

make_async ¤

make_async(func)

Decorator for slow, blocking operations. Turns them into separate threads.

matplotlib_to_image ¤

matplotlib_to_image(func)

Decorator for converting a matplotlib figure to an image.

op ¤

op(env: str, name: str, *, view='basic', outputs=None, params=None, slow=False, color=None)

Decorator for defining an operation.

op_registration ¤

op_registration(env: str)

Returns a decorator that can be used for registering functions as operations.

output_position ¤

output_position(**positions)

Decorator for specifying unusual positions for the outputs.

Example usage:

@output_position(output="top")
@op("test", "maybe add")
def maybe_add(a: list[int], b: list[int] | None = None):
    return [a + b for a, b in zip(a, b)] if b else a

parse_doc cached ¤

parse_doc(func)

Griffe is an optional dependency. When available, we return the parsed docstring.

passive_op_registration ¤

passive_op_registration(env: str)

Returns a function that can be used to register operations without associated code.

register_executor ¤

register_executor(env: str)

Decorator for registering an executor.

The executor is a function that takes a workspace and executes the operations in it. When it starts executing an operation, it should call node.publish_started() to indicate the status on the UI. When the execution is finished, it should call node.publish_result(). This will update the UI with the result of the operation.

register_passive_op ¤

register_passive_op(env: str, name: str, inputs=[], outputs=['output'], params=[], **kwargs)

A passive operation has no associated code.