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.0.1.tar.gz (5.6 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.0.1-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: shm_ring_buffer-1.0.1.tar.gz
  • Upload date:
  • Size: 5.6 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.0.1.tar.gz
Algorithm Hash digest
SHA256 df6a3f09cc86376e81c33d9d4991c6df5b077b09b4523ca7ce6f0eeb5e0741b5
MD5 655affe53467748d0f262a7e2523ebc4
BLAKE2b-256 4bf4bd62efdbdd80b0b52d66180cd249f4c254cb01e712034e48b995e81bfd15

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on loic-combis/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.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for shm_ring_buffer-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 74eedcdba13719d167ac77d7efb8a2f4aaa3b034ca710aee65fe85343203165d
MD5 896287c231063149778c6991dd5f17ac
BLAKE2b-256 61b627aae61feb87fce3e56c3f8219390e4627f0a479f62a6aaa3ed300fd238b

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on loic-combis/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