Skip to main content

A pipeline library for Python

Project description

kpipe

kpipe is a simple pipeline library that allows you to write your complex application as a pipeline. This helps code organization, debugging, and testing.

How to use

kpipe is like a DSL language inside Python. It is based on "pipes" which can be combined into pipelines using the pipe primitives provided by the library.

Each pipe represents a function transforming an input into an output. Pipes are stateless and immutable. Below is an example defining two example pipes.

from kpipeline import Pipe

class AddOnePipe(Pipe[int, int, None]):
    def apply(self, input: int, metadata: None) -> int:
        return input + 1


class MulByTwoPipe(Pipe[int, int, None]):
    def apply(self, input: int, metadata: None) -> int:
        return input * 2

These pipes can be combined using the ChainPipe primitive (aliased into the | operator) two form a pipeline that performs these two pipes sequentially:

pipeline = AddOnePipe() | MulByTwoPipe()

# or

from kpipeline import ChainPipe
pipeline = ChainPipe(AddOnePipe(), MulByTwoPipe())

print(pipeline.apply(2))  # 6

Currently, the library defines these primitives:

Primitive Purpose
ChainPipe Execute two pipes sequentially
ConditionalPipe Execute a pipe if a given condition is true
BranchPipe Execute one of two pipes depending on whether the condition is true or false
SelectPipe Execute one of multiple pipes based on a selector key
ParallelPipe Execute multiple pipes and combine their results (only async implementation is actually parallel)
MetadataWrapperPipe Transform the metadata given to the pipeline for the subpipe
MapPipe Apply a subpipe into a sequence of inputs
FilterPipe Filter a sequence of inputs using a predicate
RetryPipe Run a pipe multiple times in case it fails

Tests

You can run all tests in this repository with

uv run pytest test
uv run mypy .

License

TBD

AI Use Disclosure

I hate writing tests so unit tests have been generated by GPT-OSS 120B for your convenience. They are provided in the hope that they are better than nothing.

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

kpipeline-0.1.1.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

kpipeline-0.1.1-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file kpipeline-0.1.1.tar.gz.

File metadata

  • Download URL: kpipeline-0.1.1.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux Asahi Remix","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for kpipeline-0.1.1.tar.gz
Algorithm Hash digest
SHA256 dafd28fe469e507471a4c7d683cf08da3f01d5dcb3cd65e9df2426038b90c4ce
MD5 bf7094c51cba2139a5100399da96b39f
BLAKE2b-256 f9a8f351c41d86b1175c02b10f3250b0d06e603050ecd8fead2d9e9e7908ed07

See more details on using hashes here.

File details

Details for the file kpipeline-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: kpipeline-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux Asahi Remix","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for kpipeline-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7d7dbaa5d1d679855eb7d909939b8bc01839179c14640fb45cdf74bd0ba57349
MD5 e4a7b65d034d9a090456e9b2dacb6616
BLAKE2b-256 3bb3ae8f4fc30e3b3e81a493c8cf1c761a229929be2106ee33a1828580706d66

See more details on using hashes here.

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