Skip to main content

pyshmem

PyPI Python CI Documentation License: MIT

pyshmem is a Python library for low-latency, cross-process exchange of fixed shape NumPy arrays and CUDA-backed PyTorch tensors. CPU and GPU streams share the same small create / open / write / read API.

A pyshmem stream is a capacity-one latest-value exchange, not a queue. Each write replaces the previous payload; readers get a consistent snapshot and can inspect missed-publication counters when producers run faster than consumers. It supports Linux and macOS; CUDA IPC is Linux-only. Windows is unsupported.

Documentation · API reference · Source · Issues · Changelog

Quick start

Create and publish from one process:

import numpy as np
import pyshmem

writer = pyshmem.create("frames", shape=(480, 640), dtype=np.float32)
with writer.write_view() as frame:
    frame[...] = 1.0  # zero-copy, exception-safe publish

Attach and read from another:

import pyshmem

reader = pyshmem.open("frames")
frame = reader.read()  # latest consistent snapshot
next_frame = reader.read_new(timeout=1)  # wait for the next publication
next_frame = reader.read_after(reader.last_read_count, timeout=1)
print(reader.missed_writes)

# Keep a payload and its generation metadata inseparable when it matters.
publication = reader.read_publication()
print(publication.frame_id, publication.count, publication.payload)

reader.close()

Use the same API for CUDA by creating with gpu_device="cuda:0"; reads return a CUDA torch.Tensor when attached to the GPU. Destroy persistent streams with writer.unlink() when they are no longer needed.

See the quick start, usage guide, and GPU guide for lifecycle, locking, asyncio, CPU mirrors, failure recovery, and CLI examples.

Installation

CPU support:

pip install pyshmem

CUDA support (installs the PyTorch dependency):

pip install "pyshmem[gpu]"

See the installation guide for supported Python versions, platform requirements, development setup, and installation verification.

Performance

The repository includes both single-process microbenchmarks and a calibrated, spawned-process request/acknowledgement benchmark with an unsafe raw shared memory lower-bound comparison.

On the primary Linux development machine (Python 3.12, NumPy 2.2.6, PyTorch 2.10, RTX 5090), the spawned-process 64 KiB benchmark measured:

Implementation Round trips/s p50 p95 p99
pyshmem (CPU) 13,988 60.26 µs 111.69 µs 115.70 µs
pyshmem (GPU IPC) 4,872 189.25 µs 239.00 µs 240.98 µs
Raw shared memory polling 16,492 57.58 µs 104.45 µs 108.95 µs

The raw baseline omits pyshmem's locking, metadata validation, discovery, and consistent snapshots. The GPU row is a separate spawned process mapping the producer's CUDA tensor over torch IPC and reading a consistent device snapshot each round trip. Results are machine-specific; run the harness on the target deployment host (add --gpu for the CUDA baseline):

python benchmarks/benchmark_ipc.py \
  --payload-bytes 65536 --minimum-seconds 1 --repeats 5 --gpu

See the benchmark documentation and the versioned result for methodology, CPU/GPU measurements, and limitations.

License and contact

pyshmem is licensed under the MIT License.

Use GitHub issues for bugs and feature requests. See CONTRIBUTING.md for development, SUPPORT.md for compatibility and support scope, and SECURITY.md for private vulnerability reporting.

Metadata

Release files for pyshmem 1.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyshmem 1.3.3
File Size Uploaded
pyshmem-1.3.3.tar.gz 67.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyshmem 1.3.3
File Interpreter ABI Platform
pyshmem-1.3.3-py3-none-any.whl Python 3 none any Details

Total release size: 105.0 kB

Release files / pyshmem-1.3.3.tar.gz

Download URL pyshmem-1.3.3.tar.gz
Size 67.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9e1669a4cf4cc547fae44a25d305a79849e2492fe96aa195d55fa6b976d28eb1
BLAKE2b-256 checksum
How to use checksums
2bb71e3aa4109633abf4f8b56ea0d45561d91e32e4726846314e7f1c44708755
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 26, 2026.

Transparency log

Release files / pyshmem-1.3.3-py3-none-any.whl

Download URL pyshmem-1.3.3-py3-none-any.whl
Size 37.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b2f33c6ccb490761c7e912dcf31f250ada596e21c488e3f7cdc9ab92ceaefc3d
BLAKE2b-256 checksum
How to use checksums
b6417cc8ef005f8a3938afa73ac9dc77b8eb843260625b07bf68b03764a0ad41
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 26, 2026.

Transparency log

Release history Release notifications | RSS feed

1.3.8

2 release files

1.3.7

2 release files

1.3.6

2 release files

1.3.5

2 release files

1.3.4

2 release files

This release

1.3.3 This release

2 release files

1.3.2

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page