Skip to main content

A versatile, high-performance ring buffer implementation for Python supporting standard lists, NumPy arrays, and shared memory for inter-process communication.

Project description

Ring Buffer

A high-performance, zero-copy ring buffer implementation for Python. This library provides a seamless way to handle streaming data using standard NumPy arrays or Shared Memory for ultra-fast inter-process communication (IPC).

Key Features

  • Zero-Copy Design: Read operations return a view of the buffer rather than a copy, minimizing overhead.

  • Multiprocessing Ready: Built-in support for SharedMemory to move data between processes at lightning speed.

  • NumPy Integration: Native support for NumPy arrays, allowing for direct mathematical operations on buffer data.

  • Lock-Free Performance: Optimized for Single-Producer Single-Reader (SPSR) scenarios.

🚀 Get Started

Prerequisites

Python: 3.11 or higher

Optional: numpy (required for NumPy-specific buffer classes)

Installation

Using pip:

# Basic installation
pip install shm-ring-buffer

# With NumPy support
pip install shm-ring-buffer[numpy]

Using poetry:

# Basic installation
poetry add shm-ring-buffer

# With NumPy support
poetry add shm-ring-buffer -E numpy

🛠 Usage & Architecture

[!WARNING] Single-Producer Single-Reader (SPSR): This implementation is lock-free to maximize throughput. It is not thread-safe for multiple concurrent writers or multiple concurrent readers. Ensure your architecture follows the SPSR pattern.

Shared Memory IPC

Shared memory is the fastest method for IPC in Python. This library implements two primary shared memory buffers:

BytesShmRingBuffer: Optimized for raw byte streams.

NumpyShmRingBuffer: Optimized for structured numerical data.

Implementation Note:

One process must initialize the buffer with create=True, while the consumer/other side should set create=False. Always call .close() to properly release system resources.

The Zero-Copy Workflow

To maintain high performance, the buffer returns a view of the data.

Read: Access the current item.

Process: Use the data (or copy it if you need it to persist).

Release: You must call .release() after processing to signal that the slot is available for the producer to overwrite.

🗺️ Roadmap

  • High-performance multiprocessing.shared_memory implementation.

  • CuPy implementation for hardware acceleration via NVIDIA GPUs (CUDA).

👥 Authors

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

shm_ring_buffer-1.2.1.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

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

shm_ring_buffer-1.2.1-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file shm_ring_buffer-1.2.1.tar.gz.

File metadata

  • Download URL: shm_ring_buffer-1.2.1.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for shm_ring_buffer-1.2.1.tar.gz
Algorithm Hash digest
SHA256 0e0c559eada8e2310d305a023af26ad9ee23694a92fd78caff4dad6cf2b6d929
MD5 facab797aba5a02b1849f07a118f9619
BLAKE2b-256 85a00782bb238bd62fdab0ab6ef169a62e71925da7227ed77bbaf4454b1bdf98

See more details on using hashes here.

Provenance

The following attestation bundles were made for shm_ring_buffer-1.2.1.tar.gz:

Publisher: publish.yml on loic-combis/shm-ring-buffer

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

File details

Details for the file shm_ring_buffer-1.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for shm_ring_buffer-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e13eb0b088f549314acb6e4dd8aa2e160da3555607020da37541e7d5166cbab5
MD5 3187bc9ebbcb66161e110cd8e1559edc
BLAKE2b-256 be7f532dbc4dabd97fc98852cd6ea9d18549df03ec59a07418761e0d4171285a

See more details on using hashes here.

Provenance

The following attestation bundles were made for shm_ring_buffer-1.2.1-py3-none-any.whl:

Publisher: publish.yml on loic-combis/shm-ring-buffer

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