Skip to main content

py-sharedmemory

CI PyPI Python Downloads Coverage License Ruff Checked with mypy pre-commit

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, fully typed. Python 3.11+ on Linux, macOS, and Windows.

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.

API

Call Behavior
create_shared_memory_pair(capacity=0, *, ctx=None) Returns (sender, receiver) built from one multiprocessing context.
sender.put(obj, block=True, timeout=None) / put_nowait(obj) Copies obj into a new shared-memory block; raises queue.Full.
sender.wait_for_all_ack(timeout=None) Waits until every block is received and freed; False on timeout.
receiver.get(block=True, timeout=None) / get_nowait() Returns an independent local copy; raises queue.Empty.
close(), closed, with endpoint: Both endpoints; using a closed endpoint raises BrokenPipeError.

Development

python -m pip install -e ".[dev]"
pre-commit install
python -m pytest --cov
pre-commit run --all-files

CI runs the tests on Linux, macOS, and Windows with Python 3.11–3.15 and requires 100% branch coverage on each. Pre-commit runs Ruff, mypy (strict), and file checks.

To release, update __version__ in memory/__init__.py and the changelog, then publish a GitHub release tagged vX.Y.Z. The release workflow uploads it to PyPI.

Benchmark

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.1

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.1
File Size Uploaded Provenance Actions
py_sharedmemory-3.0.1.tar.gz 112.3 kB With provenance Details for py_sharedmemory-3.0.1.tar.gz

Built distribution (wheel)

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

Total release size: 123.2 kB

Release files / py_sharedmemory-3.0.1.tar.gz

Download URL py_sharedmemory-3.0.1.tar.gz
Size 112.3 kB
Tags Source
SHA-256 checksum
How to use checksums
997d31d28f9abbfe1e20f6edf8b856d9d176c7f4b35fb29212bd344b62dd7ff8
BLAKE2b-256 checksum
How to use checksums
05b4d771508716e278abc337d1e2d4d5b458fdc1c408042233a02db74d36a262
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 Oct 17, 2026.

Transparency log

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

Download URL py_sharedmemory-3.0.1-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7166e321aa8555d14bb3652daa8cfdd366586c70b1a7f0b5f4943854de8aabd0
BLAKE2b-256 checksum
How to use checksums
cb72c343f5dfd756033626c39a8f94f8194376d8d48574b5354a536d5586cca4
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 Oct 17, 2026.

Transparency log

Security for py-sharedmemory 3.0.1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for py_sharedmemory-3.0.1.tar.gz

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 Oct 17, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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