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.0.tar.gz (6.0 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.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: shm_ring_buffer-1.2.0.tar.gz
  • Upload date:
  • Size: 6.0 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.0.tar.gz
Algorithm Hash digest
SHA256 d4ec1b0a93ec518af1896ce29dbc94d406642c932bce82a95ce959b1c9fde211
MD5 d3ea0dcfc9045ee4bb6056f1486e3e29
BLAKE2b-256 9d66e5c42d851da5ea01fadf8a6f3262e9c659faf9432aed44ee0d85da522120

See more details on using hashes here.

Provenance

The following attestation bundles were made for shm_ring_buffer-1.2.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for shm_ring_buffer-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 13cbd7336c38d974bc0585a4773e1f471f6fbc50e2d170e4f9f7be531a70d3ba
MD5 5e6f21eca6a9839719b24d70651807f2
BLAKE2b-256 5842b778981d965d9d8eef952a5a68adc544d611c3ccd4368b9b0511328a1fa8

See more details on using hashes here.

Provenance

The following attestation bundles were made for shm_ring_buffer-1.2.0-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