Skip to content

Group(iterable=())

A container for managing and executing a collection of pipelines or sub-groups.

Group allows multiple Pipeline instances or nested Group instances to be organized, executed, and controlled together as a single unit.

A Group cannot contain itself.

Pipelines and sub-groups in a group can be started, stopped, or waited on collectively.
The group also supports common sequence operations such as indexing, iteration, and length inspection.

Example:

from pipeline import Group, Pipeline

p1 = Pipeline([(lambda x: x + 1,)])
p2 = Pipeline([(lambda x: x * 2,)])

group = Group([p1, p2])
group.run(5).wait()

Args:
iterable: An iterable containing Pipeline or Group instances.
Defaults to an empty group.

Raises:
TypeError: If iterable is not iterable, or if any item is not a Pipeline or Group.
ValueError: If a group attempts to contain itself.

Execution

run(*args, **kwargs)

Start all pipelines in the group.

Passes all positional and keyword arguments to each pipeline's run() method.

Args:
args: Positional arguments forwarded to each pipeline's run() method.
kwargs: Keyword arguments forwarded to each pipeline's run() method.

Returns:
This group instance.

__call__(*args, **kwargs)

Start all pipelines in the group.

Equivalent to calling run(*args, **kwargs).

Args:
args: Positional arguments forwarded to run().
kwargs: Keyword arguments forwarded to run().

Returns:
This group instance.

wait(timeout=None)

Wait for all pipelines in the group to complete execution.

Args:
timeout: Maximum time in seconds to wait for each pipeline.
Defaults to None (wait indefinitely).

Returns:
This group instance.

stop()

Stop execution of all pipelines in the group.

Returns:
This group instance.

Pipeline and sub-group Management

add(pipeline)

Append a pipeline or sub-group to the end of the group.

Args:
pipeline: A Pipeline or Group instance to add.

Returns:
This group instance.

Raises:
TypeError: If pipeline is not a Pipeline or Group.
ValueError: If pipeline is this group.

insert(index, pipeline)

Insert a pipeline or sub-group at the given zero-based index.

Args:
index: The zero-based integer position at which to insert.
pipeline: A Pipeline or Group instance to insert.

Returns:
This group instance.

Raises:
TypeError: If index is not an integer, or if pipeline is not a Pipeline or Group.
ValueError: If index is negative, or if pipeline is this group.

extend(iterable)

Extend the group by appending pipelines and sub-groups from an iterable.

Args:
iterable: An iterable containing Pipeline or Group instances.

Returns:
This group instance.

Raises:
TypeError: If iterable is not iterable, or if any item is not a Pipeline or Group.
ValueError: If any item is this group.

remove(pipeline)

Remove the first occurrence of a pipeline or sub-group from the group.

Args:
pipeline: The Pipeline or Group instance to remove.

Returns:
This group instance.

Raises:
TypeError: If pipeline is not a Pipeline or Group.
ValueError: If pipeline is not found in the group.

pop(index)

Remove and return the pipeline or sub-group at the given zero-based index.

Args:
index: The zero-based integer index of the item to remove.

Returns:
The removed Pipeline or Group instance.

Raises:
TypeError: If index is not an integer.
ValueError: If index is negative.
IndexError: If index is out of range.

clear()

Remove all pipelines and sub-groups from the group.

Returns:
This group instance.

reverse()

Reverse the order of pipelines and sub-groups in the group in place.

Returns:
This group instance.

index(pipeline)

Return the zero-based index of the first occurrence of a pipeline or sub-group.

Args:
pipeline: The Pipeline or Group instance to search for.

Returns:
The zero-based index of the matching pipeline or sub-group.

Raises:
TypeError: If pipeline is not a Pipeline or Group.
ValueError: If pipeline is not found in the group.

count(pipeline)

Return the number of occurrences of a pipeline or sub-group in the group.

Args:
pipeline: The Pipeline or Group instance to count.

Returns:
The number of times pipeline occurs in the group.

Raises:
TypeError: If pipeline is not a Pipeline or Group.

Item Access

__getitem__(index)

Return the pipeline or sub-group at the given zero-based index.

Args:
index: Zero-based integer index of the item to retrieve.

Returns:
The Pipeline or Group at the specified index.

Raises:
TypeError: If index is not an integer.
ValueError: If index is negative.
IndexError: If index is out of range.

__setitem__(index, pipeline)

Set the pipeline or sub-group at the given zero-based index.

Args:
index: Zero-based integer index of the item to replace.
pipeline: A Pipeline or Group instance to assign.

Raises:
TypeError: If index is not an integer, or if pipeline is not a Pipeline or Group.
ValueError: If index is negative, or if pipeline is this group.
IndexError: If index is out of range.

__delitem__(index)

Delete the pipeline or sub-group at the given zero-based index.

Args:
index: Zero-based integer index of the item to delete.

Raises:
TypeError: If index is not an integer.
ValueError: If index is negative.
IndexError: If index is out of range.

Copying

copy()

Return a shallow copy of the group.

Returns:
A new Group instance containing references to the same pipelines and sub-groups.

__copy__()

Return a shallow copy of the group.

Iteration

__iter__()

Iterate over the pipelines and sub-groups in the group.

Yields:
Each Pipeline or Group in the group in order.

__reversed__()

Return an iterator that yields pipelines and sub-groups in reverse order.

Returns:
A reverse iterator over the pipelines and sub-groups in the group.

Protocols

__bool__()

Return whether the group contains at least one pipeline or sub-group.

Returns:
True if the group is non-empty, otherwise False.

__len__()

Return the number of pipelines and sub-groups in the group.

__contains__(pipeline)

Return whether a pipeline or sub-group exists in the group.

Args:
pipeline: The Pipeline or Group instance to search for.

Returns:
True if pipeline is found in the group, otherwise False.

Raises:
TypeError: If pipeline is not a Pipeline or Group.

String Representation

__repr__()

Return a string representation of the group.

Comparison

__eq__(other)

Return whether this group is equal to another group.

Args:
other: The object to compare with.

Returns:
True if other contains the same pipelines and sub-groups in the same order, otherwise False.