Skip to main content

A lightweight, object-orientated pipeline framework in Python

Project description

Pipelining

A lightweight, object-orientated pipeline framework in Python, with Rich-powered logging, and abstract semantics.

Features

  • Modular Stages: Each processing step can be defined by subclassing the simple Stage interface.
  • Pipeline Orchestration: Stages can be composed into ordered pipelines with automatic logging injection.
  • Pretty Logging: Good looking logging, powered by Rich
  • Concurrency: The MultiStepStage supports parallelism of tasks.

Installation

This package is built for Python 3.13, as that is the version I use the most. I am happy to extend it for other versions.

Install pipelining-colemann through PyPi with:

$ pip install pipelining-colemann
...

Example

class TextStage(Stage):
    def __init__(self, name: str, message: str) -> None:
        super().__init__(name)
        self.message = message

    def run(self, context: dict[str, Any]) -> None:
        self.logger.info(f"{self.name}: {self.message}")


pipeline = Pipeline(
    [TextStage("Stage 1", "Hello, World!"), TextStage("Stage 2", "Goodbye, World!")],
    name="Example Pipeline",
)

pipeline.run()

A simple example like this will output:

[2025-05-07 17:52:18] INFO     Starting Example Pipeline                                                                                                                           
                      INFO     Running stage: TextStage                                                                                                                            
                      INFO     Stage 1: Hello, World!                                                                                                                              
                      INFO     Stage TextStage completed successfully!                                                                                                             
                      INFO     Running stage: TextStage                                                                                                                            
                      INFO     Stage 2: Goodbye, World!                                                                                                                            
                      INFO     Stage TextStage completed successfully!                                                                                                             
                      INFO     Example Pipeline completed successfully!                                                                                                            

Concurrency Example

class TextStage(Stage):
    def __init__(self, name: str, message: str) -> None:
        super().__init__(name)
        self.message = message

    def run(self, _: dict[str, Any]) -> None:
        self.logger.info(f"{self.name}: {self.message}")


def make_step(name: str, delay: float = 0.1) -> Callable:
    def step(context):
        sleep(delay)
        context[name] = f"{name}_done"

    return step


multistep_stage = MultiStepStage(
    name="Multi-Step Stage Example",
    steps=[
        make_step("Step A", delay=0.2),
        make_step("Step B", delay=5),
        make_step("Step C", delay=0.1),
    ],
    parallel=True,
)

text_one = TextStage(name="Text Stage One", message="This is the first text stage.")
text_two = TextStage(name="Text Stage Two", message="This is the second text stage.")

pipeline = Pipeline(
    stages=[text_one, multistep_stage, text_two], name="Example Pipeline"
)

context: dict[str, Any] = {}

pipeline.run(context=context, use_tqdm=True)

This is an example of a pipeline with both normal and multi-step stages - with the multi-step stage running its steps in parallel.

Development

To setup a Python environment for this project, I recommend using Pixi - I use it and like it. You can enter the workspace using:

$ pixi shell
...

The following self-explanatory tasks are available for usage.

  • ruff
  • mypy
  • test
  • coverage

Testing

Tests can be run through Pixi with:

$ pixi run test
...

They can be run with coverage too, this will generate a coverage report under the htmlcov directory.

$ pixi run coverage
...

Contributing

Feel free to contribute to the project! I would appreciate any feedback or comments. Although this project has been built with my own usage in mind, I'm open to changes and improvements.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pipelining_colemann-0.0.2.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pipelining_colemann-0.0.2-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file pipelining_colemann-0.0.2.tar.gz.

File metadata

  • Download URL: pipelining_colemann-0.0.2.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pipelining_colemann-0.0.2.tar.gz
Algorithm Hash digest
SHA256 e5a1fad9a85b63871d3fbad1a2e96853fc40eb5a582b522be128610082e56dcf
MD5 502b7002983c737851c251eef99167f7
BLAKE2b-256 33da73850058ce4ef093731ec263fd77e66d885a356996961e31e183fdc90a55

See more details on using hashes here.

Provenance

The following attestation bundles were made for pipelining_colemann-0.0.2.tar.gz:

Publisher: publishing.yml on colemannoah/pipelining

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pipelining_colemann-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pipelining_colemann-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0f413ed579ac21fb7eb942d473be575cf7c3793ea1a5ef509d37f67f19ca3fd3
MD5 9bbd1a95696a868ad59b602f9bed4dd5
BLAKE2b-256 82ed1a979bf5c67ead274dce493122e45f86e6b3e6cfee05c839796a03a81a9c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pipelining_colemann-0.0.2-py3-none-any.whl:

Publisher: publishing.yml on colemannoah/pipelining

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page