Skip to main content

SmartPipeline

A framework for rapid development of robust data pipelines following a simple design pattern

pipeline comic

from https://xkcd.com

Documentation Status Tests Tests Coverage

SmartPipeline gives you the tools to design simple data pipelines, in which each task is encapsulated in a pipeline stage.

It is straightforward to implement a pipeline, but stages are deeply customizable: they follow a producer-consumer pattern and can run concurrently to scale heavy tasks, they can process batches of items at once, and executions and errors can be monitored easily.

It is a good fit for fast and clean data analysis prototypes (small/medium projects and POCs), as well as production code, as an alternative to plain scripts. Use it when big task queues and workflow frameworks are overkill. No dependencies are required.

Install

Install from PyPI, no dependencies will be installed:

pip install smartpipeline

Writing your pipeline

SmartPipeline is designed to help the developer follow best practices, the design is based on industrial experience with data products.

SmartPipeline focuses on simplicity and efficiency in handling data locally, i.e. serialization and copies of the data are minimized.

Main features:

  • Define a pipeline as a sequence of stateful stages, optionally with a source the pipeline iterates over.

  • Run the pipeline over the source, indefinitely if needed, or use it to process single items.

  • Set concurrency independently for each stage, and process single items asynchronously.

  • Design stages that process batches, i.e. groups of consecutive items, at once.

  • Customize error handling for logging and monitoring at stage level.

For example, this pipeline retrieves news from a feed and generates text embeddings of the page contents. We define the source of the data and two stages, then we build and run the pipeline.

import re
from typing import Generator, Sequence, TypedDict

import feedparser
import requests
from sentence_transformers import SentenceTransformer

from smartpipeline import BatchStage, Item, Pipeline, Stage


class NewsData(TypedDict):
    url: str
    content: str
    vector: list[float]


def feed() -> Generator[Item[NewsData], None, None]:
    parsed = feedparser.parse("https://hnrss.org/newest")
    for entry in parsed.entries:
        yield Item[NewsData]({"url": entry.link, "content": "", "vector": []})


class NewsRetrieve(Stage[NewsData]):
    def process(self, item: Item[NewsData]) -> Item[NewsData]:
        # add the page content to each item,
        # HTTP errors are handled by the pipeline error manager
        html = requests.get(item.data["url"]).text
        item.data["content"] = re.sub('<.*?>', '', html).strip()
        return item


class NewsEmbedding(BatchStage[NewsData]):
    def __init__(self, size: int):
        super().__init__(size)
        self.model = SentenceTransformer("all-MiniLM-L6-v2")

    def process_batch(
        self, items: Sequence[Item[NewsData]]
    ) -> Sequence[Item[NewsData]]:
        # efficiently compute embeddings by batching page texts,
        # instead of processing one page at a time
        vectors = self.model.encode([item.data["content"] for item in items])
        for vector, item in zip(vectors, items):
            item.data["vector"] = vector
        return items


pipeline: Pipeline[NewsData] = (
    Pipeline[NewsData]()
    .set_source(feed())
    # with threads (the default) we speed up the multiple HTTP calls
    .append("retriever", NewsRetrieve(), concurrency=4)
    # each batch of items to vectorize will be of size 10
    .append("vectorizer", NewsEmbedding(size=10))
    .build()
)


for item in pipeline.run():
    print(item)

Read the documentation for the full guide.

The examples folder contains full working sample pipelines.

AI code agents note

Since version 1.0.0 the codebase development is supported by LLM code agents, strictly using open-source tools and open-weight models, always human reviewed.

Metadata

Release files for SmartPipeline 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for SmartPipeline 1.0.0
File Size Uploaded Provenance Actions
smartpipeline-1.0.0.tar.gz 63.1 kB Without provenance Details for smartpipeline-1.0.0.tar.gz

Release files / smartpipeline-1.0.0.tar.gz

Download URL smartpipeline-1.0.0.tar.gz
Size 63.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2faee848217988e537d20cf966f56af13bca8ad24b0057da2b6614bbbdd8a244
BLAKE2b-256 checksum
How to use checksums
9ebac11eee4b8c0f78c44f638e305e85fc3513e1658a32a15f5ab2c7237bbb78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for SmartPipeline 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page