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.1.0.tar.gz (5.9 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.1.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: shm_ring_buffer-1.1.0.tar.gz
  • Upload date:
  • Size: 5.9 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.1.0.tar.gz
Algorithm Hash digest
SHA256 982ae70dd76dac9565324844e8bcbe4be5c12de3ab82b9d7e496d2092c4e6d63
MD5 385574bd0407f75b4de7b2f0295802d7
BLAKE2b-256 587f3f1c3b6aa62b397450682e21742a59f7048507d0a9933781c83436ae3033

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for shm_ring_buffer-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 011559ab9d70a53db815adc8103772c12c8b359b6614d5ac14068ce0cb9649de
MD5 83e748570cf674b8ea1caf60b85d6459
BLAKE2b-256 46d7dda920c1e2fa5b21612ca2ea06f4550c0fdd36d0d15351c35aaf127795f3

See more details on using hashes here.

Provenance

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