GuidesAPI reference
DiscordDashboard
DiscordDashboard

pipeline.Variable

Variable - class

Source on GitHub

pipeline.objects.variable.Variable(
	type_class: Any,
  *,
  is_input: bool = False,
  is_output: bool = False,
  name: str = None,
  remote_id: str = None,
  local_id: str = None
)

Description

The Variable class acts as an input/output to nodes in the pipeline computation graph, or as input/output to the whole pipeline. It does not explicitly contain a value when defined in the context manager, but is used to refer to a value that will exist when the pipeline is run.

The Variable class is instantiated either explicitly by the user, or created and returned by a pipeline_function when that function is used in the Pipeline context manager. It can only be defined when the Pipeline context manager is active.

Input Variable objects must be manually added to the context manager builder, and the builder must be notified of output Variable objects. See the example below.

Parameters

  • is_input (bool, optional) - states whether this variable is expected to be an input to the pipeline when the pipeline run function is called.
  • is_output (bool, optional) - states whether this variable is returned from the pipeline run function when called.
  • name (str, optional) - the name of the variable
  • remote_id (str, optional) - the ID of the variable on a remote system. Not currently used.
  • local_id (str, optional) - the local UID of the variable that is referenced by graph nodes

Examples

Creating an input Variable

from pipeline import Pipeline, Variable, pipeline_function


@pipeline_function
def add_numbers(a: int, b: int) -> int:
    return a + b


with Pipeline("add-numbers") as pipeline:
    a = Variable(type_class=int, is_input=True)
    b = Variable(type_class=int, is_input=True)
    pipeline.add_variables(a, b)

    c = add_numbers(a, b)

    pipeline.output(c)