Skip to main content

No project description provided

Project description

Pipeline

Multithread python pipeline framework.

  • Preserving first-in-first-out order of data.
  • Supporting complex and non-linear data flow.
  • Maximizing thouroughput.
  • Easy and intuitive. Minimal code to build a pipeline.
  • Suitable for IO-bound and numpy/pytorch-based applications with complex streamed data.

Installation

pip install git+https://github.com/EasternJournalist/pipeline.git

Supported Components

Category Component Description
Basic Worker Applies a user-defined function to each input item.
Source Generates data into the pipeline; usually the starting point.
Structural Sequential Pipeline of nodes in a sequential order.
Parallel Runs a pool of parallel nodes.
Batching & Flow Control Batch Groups incoming items into batches of a given size, or within time of patience.
Unbatch Splits batched input into individual items.
Buffer Buffers items in a queue between upstream and downstream stages.
Filter Filter items.
Multi-Branch Routing Distribute Takes a dictionary input and sends each value to corresponding named branch.
Broadcast Sends a copy of input to all branches.
Switch Uses a key function to send data to a single selected branch.
Router Uses a key function to send data to multiple selected branches.

Example

graph TD
    A["**A** (30ms)"] --> B_in
    
    subgraph Parallel Worker Pool
      B_in((Pool)) --> B1["**B1** (150ms)"] & B2["**B2** (150ms)"] & B3["**B3** (150ms)"] --> B_out((Pool))
    end
    B_out --> C_in

    subgraph Distributed Block **C**
      C_in[/Split\]
      C_out[\Merge/]
      C_in -->|x| CX["**CX** (40ms)"] --> C_out
      C_in -->|y| CY_in 
      
      subgraph Parallel Worker Pool **CY**
        CY_in((Pool)) --> CY1["**CY1** (120ms)"] & CY2["**CY2** (120ms)"] & CY3["**CY3** (120ms)"] --> CY_out((Pool))
      end
      CY_out --> C_out
    end
    C_out --> D["**D** (40ms)"]
  • If processing serially, each item takes 30 + 150 + 40 + 120 + 40 = 380ms.
  • With pipeline, we can achieve the theoretical optimal throughput of 50ms per item.
import pipeline

pipe = pipeline.Sequential([ 
    A, 
    pipeline.Parallel([B, B, B]),
    pipeline.Distribute({
      'x': CX, 
      'y': pipeline.Parallel([CY, CY, CY]), 
    }),  .
    D,
])

Test the full example code below:

import time
import pipeline

# Define the functions of each node
def A(data):
    time.sleep(0.03)
    return data * 4 - 3

def B(data):
    time.sleep(0.15)
    return {'x': data * 2, 'y': 1}

def CX(data):
    time.sleep(0.04)
    return data ** 2

def CY(data):
    time.sleep(0.12)
    return data - 1

def D(data):
    time.sleep(0.05)
    return data['x'] + data['y']


# Build the pipeline
pipe = pipeline.Sequential([ 
    A, 
    pipeline.Parallel([B, B, B]),
    pipeline.Distribute({
      'x': CX, 
      'y': pipeline.Parallel([CY, CY, CY]), 
    }),
    D,
])

# Start the pipeline and run it
with pipe:  
    
    last_time = time.time()
    # Pass an iterable input to the pipeline and iterate over the results
    for i, result in zip(range(100), pipe(range(100))):
        now = time.time()
        print(f"No. {i}, result: {result}, throughput: {now - last_time:.4f}s/it.")
        last_time = now

    # Usage 2 - For irregularlly sourced data
    pipe.put(10)
    print(pipe.get())

    # NOTE for usage 2: 
    # If you put too many data and do not get them, 
    # the pipeline will be full, and the put operation will block until the pipeline has space to accept the data.
    # Consider putting data in a separate thread.
    # Or use a Buffer(0) node at the beginning of the sequential to hold infinite number of inputs.

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

dlr_pipeline-1.0.0.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

dlr_pipeline-1.0.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file dlr_pipeline-1.0.0.tar.gz.

File metadata

  • Download URL: dlr_pipeline-1.0.0.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for dlr_pipeline-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0180e1cde9edd64d20281085f09e18dc520114ae4821aca35f6ecc17b19de154
MD5 df3b2d6af4791b62b3438b8fcab822b1
BLAKE2b-256 0453f1037cd9f6d533509c93da6688c31f4458e29f5a00abb699333c15223977

See more details on using hashes here.

File details

Details for the file dlr_pipeline-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: dlr_pipeline-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for dlr_pipeline-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 31a0651f498fc1a8a3ad4c9def5fa006a791ea0952bdd5ff42fd93477cb445ed
MD5 3e7652a5808ce558476df6625d04608b
BLAKE2b-256 34f8d122bfacedc7204918a6efdd280f28d90cc00e1bd176f82f5af42f93c050

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