Skip to main content

py-sharedmemory

Send large Python objects between processes with less pipe I/O.

Originally built to reduce the heavy Windows pipe I/O and uneven throughput caused by large multiprocessing.Queue transfers. Payloads travel through shared memory; queues carry only small metadata, avoiding bulk transfers through the pipe.

Useful for ML pipelines, reinforcement-learning actors and replay buffers, scientific computing, and image/video processing. Supports pickleable Python objects with familiar put/get calls. No runtime dependencies. Python 3.11+.

pip install py-sharedmemory

Measured performance

Transfer speed relative to multiprocessing.Queue, from 16 bytes to 10 GB

About 2× faster at 1–10 MB; 10 GB transferred in 8.0 s. mp.Queue failed at 10 GB (Windows error 87). Small messages favor standard queues.

Core i9-14900K, 191.8 GiB RAM, Windows 11, Python 3.12.10, NumPy 2.5.3. 2026-10-08; contiguous float32 arrays; spawn; capacity 2; median of 5 runs, excluding startup and warmup. Up to 1,000 messages or 512 MiB/run, at least one message. GB = 10⁹ bytes. Raw results. These measurements show transfer speed; I/O and stability depend on the workload.

Usage

import multiprocessing as mp
from memory import create_shared_memory_pair


def produce(sender):
    with sender:
        sender.put({"step": 42, "frames": bytearray(16_000_000)})
        sender.wait_for_all_ack()


if __name__ == "__main__":
    ctx = mp.get_context("spawn")
    sender, receiver = create_shared_memory_pair(capacity=2, ctx=ctx)
    worker = ctx.Process(target=produce, args=(sender,))
    worker.start()
    with receiver:
        batch = receiver.get(timeout=30)
    worker.join()
    sender.close()

One producing process per pair; multiple threads and consumers are supported. Pass endpoints to workers before use. put/get support block, timeout, and *_nowait. Capacity counts outstanding messages; 0/None is unbounded.

Drain before producer close or exit: wait_for_all_ack(timeout=...) returns False on timeout. Close discards unread data. Within one process, drain before closing either endpoint. Received data stays valid after cleanup; arrays preserve mutability.

A complete example includes error handling.

Test and benchmark

python -m pip install -e ".[test,benchmark]"
python -m pytest --cov=memory
python -m benchmarks.benchmark --sizes 16 100 1000 10000 100000 1000000 10000000 100000000 1000000000 10000000000 --repeats 5 --json benchmarks/results/windows-numpy.json
python -m benchmarks.plot benchmarks/results/windows-numpy.json benchmarks/results/windows-numpy.png

The full benchmark needs enough RAM for several payload copies.

Metadata

Release files for py-sharedmemory 3.0.0

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

Source distribution (sdist)

Source distribution for py-sharedmemory 3.0.0
File Size Uploaded
py_sharedmemory-3.0.0.tar.gz 108.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-sharedmemory 3.0.0
File Interpreter ABI Platform
py_sharedmemory-3.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 117.1 kB

Release files / py_sharedmemory-3.0.0.tar.gz

Download URL py_sharedmemory-3.0.0.tar.gz
Size 108.0 kB
Tags Source
SHA-256 checksum
How to use checksums
56a746f72e7f1eb11312308ef9dd0116ca12409c3178fd6d710124d5261a8aa5
BLAKE2b-256 checksum
How to use checksums
588337eaaa22abbeb12bc588365a29be9d1238e2c92ed86ade8bb10892829231
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / py_sharedmemory-3.0.0-py3-none-any.whl

Download URL py_sharedmemory-3.0.0-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7499c23ab6aa8d676dd0b44e70bb3c498ff73285bdd03433f0d9858460bd3767
BLAKE2b-256 checksum
How to use checksums
349758953532ed9d22343594d2e2498105cdc42cbb2ccb7fa3f0c69a37f399ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release history Release notifications | RSS feed

This release

3.0.0 This release

2 release files

2.0.1

2 release files

2.0.0

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