Skip to main content

A pipe-based I/O library for efficient data transfer between threads with filtering support

Project description

QueuePipeIO

A Python library that provides a pipe-based I/O system for efficient data transfer between threads, with support for data transformation filters and memory management.

Features

  • Unidirectional Pipes: Separate PipeWriter and PipeReader classes for clear data flow
  • Pipe Operator: Chain components using the | operator (like Unix pipes)
  • Memory Management: Built-in backpressure with configurable memory limits
  • Data Filters: Transform data as it flows through the pipeline (e.g., hash computation)
  • Thread-Safe: Designed for multi-threaded producer/consumer patterns
  • S3 Integration: Optimized for streaming large files to/from S3 with integrity verification

Installation

pip install queuepipeio

Quick Start

Basic Usage

from queuepipeio import PipeWriter, PipeReader

# Create a pipe
writer = PipeWriter()
reader = PipeReader()
writer | reader  # Connect with pipe operator

# In producer thread
writer.write(b"Hello, World!")
writer.close()

# In consumer thread
data = reader.read()
print(data)  # b"Hello, World!"

With Memory Limit

from queuepipeio import PipeWriter, PipeReader

MB = 1024 * 1024

# Limit memory usage to 10MB
writer = PipeWriter(memory_limit=10*MB, chunk_size=1*MB)
reader = PipeReader()
writer | reader

# Memory limit provides backpressure if consumer is slower
# Writer will block when queue is full

Pipeline with Hash Computation

from queuepipeio import PipeWriter, PipeReader, HashingFilter

# Create a pipeline: writer -> hasher -> reader
writer = PipeWriter()
hasher = HashingFilter(algorithm='sha256')
reader = PipeReader()

# Chain components
writer | hasher | reader

# Write data
writer.write(b"Important data")
writer.close()

# Read data (unchanged)
data = reader.read()

# Get computed hash
file_hash = hasher.get_hash()
print(f"SHA256: {file_hash}")

Real-World Example: S3 Streaming with Verification

import boto3
import threading
from queuepipeio import PipeWriter, PipeReader, HashingFilter

def stream_s3_download(s3_client, bucket, key, local_file):
    """Download from S3 with hash verification"""
    
    # Create pipeline
    writer = PipeWriter(memory_limit=50*1024*1024)  # 50MB limit
    hasher = HashingFilter('sha256')
    reader = PipeReader()
    
    writer | hasher | reader
    
    def download_thread():
        """Download from S3 to pipe"""
        response = s3_client.get_object(Bucket=bucket, Key=key)
        
        for chunk in response['Body'].iter_chunks(chunk_size=1024*1024):
            writer.write(chunk)
        
        writer.close()
    
    def save_thread():
        """Read from pipe and save to file"""
        with open(local_file, 'wb') as f:
            while True:
                chunk = reader.read(1024*1024)
                if not chunk:
                    break
                f.write(chunk)
    
    # Start threads
    dl_thread = threading.Thread(target=download_thread)
    save_thread = threading.Thread(target=save_thread)
    
    dl_thread.start()
    save_thread.start()
    
    dl_thread.join()
    save_thread.join()
    
    # Return computed hash for verification
    return hasher.get_hash()

Architecture

Core Components

  • PipeWriter: Write-only endpoint that puts data into a queue
  • PipeReader: Read-only endpoint that reads data from a queue
  • PipeFilter: Base class for data transformation filters
  • HashingFilter: Computes hash of data passing through

Key Benefits

  • No Deadlocks: Unidirectional flow eliminates race conditions
  • Composable: Easy to chain components and add filters
  • Memory Efficient: Automatic backpressure prevents memory overflow
  • High Performance: Minimal overhead, suitable for large file transfers

Testing

# Run all tests
python -m unittest discover -s tests

# Run with S3 integration tests (requires Docker)
# S3 tests automatically start LocalStack if needed
python -m unittest tests.test_s3_integration -v

# Keep LocalStack running between test runs
KEEP_LOCALSTACK=true python -m unittest discover -s tests

Migration from Old API

If you're using the old QueueIO class:

# Old way
from queuepipeio import QueueIO
qio = QueueIO()
qio.write(data)
result = qio.read()

# New way  
from queuepipeio import PipeWriter, PipeReader
writer = PipeWriter()
reader = PipeReader()
writer | reader
writer.write(data)
writer.close()
result = reader.read()

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

queuepipeio-0.1.14.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

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

queuepipeio-0.1.14-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file queuepipeio-0.1.14.tar.gz.

File metadata

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

File hashes

Hashes for queuepipeio-0.1.14.tar.gz
Algorithm Hash digest
SHA256 61c8ec29100040230f257eb3f6a32f263c33e5bc9f521b86a695f766c3aebeb1
MD5 a841672687ef78406e538224fdacb79a
BLAKE2b-256 310384bb590f66e94554321c2c2ddd679a10427769b93fdebf21527aba78f2b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for queuepipeio-0.1.14.tar.gz:

Publisher: publish-to-pypi.yml on dangeReis/QueuePipeIO

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

File details

Details for the file queuepipeio-0.1.14-py3-none-any.whl.

File metadata

  • Download URL: queuepipeio-0.1.14-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for queuepipeio-0.1.14-py3-none-any.whl
Algorithm Hash digest
SHA256 5b2ca49653a08cef6074d5f38a7d079fe98e624a1e0f7e7e8292f5e8dd45d490
MD5 836699b6516be2f6d85f6abd4ea9d95b
BLAKE2b-256 31f3431b645670473a23ab393bd8f0e3deba506be2c13c2dcb633ebed8ca4c32

See more details on using hashes here.

Provenance

The following attestation bundles were made for queuepipeio-0.1.14-py3-none-any.whl:

Publisher: publish-to-pypi.yml on dangeReis/QueuePipeIO

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