pipeline.links
Link classes for the pipeline framework.
Contains:
LinkList: list subclass supporting the | operator to combine links
Link: connects an output port of one module to an input port of another
ConditionalLink: a Link that transfers data only when a runtime condition is True
Classes
- class pipeline.links.LinkList
A list subclass that supports the | operator for chaining Link objects.
- Inherits from:
list
- class pipeline.links.Link
A link to link the output port of parent module and input port of child module.
Methods:
- __init__(parent: PipeModule | PortReference, child: PipeModule | PortReference, port_out: str | None = None, port_in: str | None = None, lname: str | None = None) None
Initialize the Link object.
Parameters
- parentPipeModule | PortReference
The parent module or a PortReference for the output port.
- childPipeModule | PortReference
The child module or a PortReference for the input port.
- port_outstr, default: None
The output port name of the parent module. When it’s None, the first output port will be used. Ignored if parent is a PortReference.
- port_instr, default: None
The input port name of the child module. When it’s None, the first input port will be used. Ignored if child is a PortReference.
- connect(connection: tuple) Link
Create a Link from a tuple of PortReference objects.
Parameters
- connectiontuple
A tuple of (output_port_reference, input_port_reference)
Returns
- Any
Link The created link
Examples
>>> link = Link.connect((parent.OutputPort, child.InputPort))
- chain() list[Link]
Create multiple Links from chained connections.
Parameters
- *connectionsPortReference or Link
Chain of connections using >> operator or existing Link objects
Returns
- Any
list[Link] List of created links
Examples
>>> links = Link.chain( ... parent.OutputPort >> child.InputPort, ... child.OutputResult >> final.InputData ... )
- when(condition: Callable[[PipeModule], bool] | str) ConditionalLink
Convert this link into a ConditionalLink with a runtime condition.
Auto-detects the condition type from the argument: - **Callable** → used directly as the condition function (Python-only, not serializable into .pipe files). Signature: ````condition(parent_module: PipeModule) -> bool```` - **str that is a valid Python identifier** → treated as ````condition_name````: the name of a function in the pipeline's ````local_functions_path```` file. Fully serializable. - **str with operators / spaces** → treated as ````condition_expr````: a Python expression evaluated with the parent module's output port data and
Parameters
- conditionCallable | str
The condition to apply. Type is auto-detected as described above.
Returns
- Any
ConditionalLink
Examples
>>> # Expression string – port data available by name >>> (scorer.OutputScore >> grader.InputData).when("OutputScore > 0.5") >>> # Function name – resolved from pipeline.local_functions_path >>> (scorer.OutputScore >> grader.InputData).when("check_score_valid") >>> # Callable – convenient but not serializable >>> (scorer.OutputScore >> grader.InputData).when( ... lambda m: m["OutputScore"] is not None and m["OutputScore"] > 0.5 ... )
- class pipeline.links.ConditionalLink
A Link that only transfers data when a runtime condition evaluates to True.
When the condition evaluates to False, the link and all its downstream descendants are skipped for that pipeline run — no data is transferred and the child module is not executed. Three ways to specify a condition (evaluated in priority order): #. **condition** (Callable) — a Python callable for interactive / script use. Not serializable into ````.pipe```` files. Signature: ````condition(parent_module: PipeModule) -> bool```` #. **condition_name** (str, valid Python identifier) — the name of a function in the pipeline's ````local_functions_path```` file. Fully serializable. The function must accept a single ````PipeModule```` argument and return ````bool````. #. **condition_expr** (str, expression) — a Python expression evaluated with the parent module's output port data and attributes available as variables. Fully serializable. Port names always start with ````Input````/````Output````, so they never collide with attribute names in the evaluation context.
Parameters
- parentPipeModule | PortReference
Source module or output PortReference.
- childPipeModule | PortReference
Target module or input PortReference. port_out : str, optional Output port name on the parent (auto-selected if None). port_in : str, optional Input port name on the child (auto-selected if None). lname : str, optional Custom link name. condition : Callable[[PipeModule], bool], optional Runtime callable. Takes the parent module and returns bool. condition_name : str, optional Name of a function in
``pipeline.local_functions_path``. condition_expr : str, optional Python expression string. Parent output ports and attributes are available as variables by their names.
Examples
>>> # Fluent API (recommended) >>> (scorer.OutputScore >> grader.InputData).when("OutputScore > 0.5") >>> # Direct construction with expression >>> ConditionalLink( ... scorer.OutputScore, grader.InputData, ... condition_expr="OutputScore > 0.5", ... ) >>> # Direct construction with function name >>> ConditionalLink( ... scorer.OutputScore, grader.InputData, ... condition_name="check_score_valid", ... )
- Inherits from:
Link
Methods:
- __init__(parent: PipeModule | PortReference, child: PipeModule | PortReference, port_out: str | None = None, port_in: str | None = None, lname: str | None = None, condition: Callable[[PipeModule], bool] | None = None, condition_name: str | None = None, condition_expr: str | None = None) None
- evaluate(parent_module: PipeModule, local_functions_path: str | Path | None = None) bool
Evaluate the condition against the parent module.
Condition types are tried in priority order: callable → condition_name → condition_expr. Returns
``True``when no condition is set (acts as a regular unconditional link).Parameters
- parent_modulePipeModule
The parent module whose ports and attributes are exposed to the condition. local_functions_path : str | Path, optional Path to the local functions file; required when
``condition_name``is set.
Returns
- Any
bool Whether the link should transfer data and trigger child execution.