Skip to main content

Overview

ndarray + sharing = ndsharray

Introduction

This python module let you share a numpy ndarray within different processes (either via python's multiprocessing or sharing between different python instances). The library behind this package is the lib mmap from official python - no extra library, except numpy, is needed. The mmap approach is using the shared memory, which can be accessed by different CPUs/python instances. Using shared memory is much faster than the pickle approach - you can even do a video streaming on a Raspberry Pi / Jetson Nano over multiple python processes.
This library is easy-to-use, just initialize the shared array with a unique tag and write/read! You can even change the numpy array dimension/shape/dtype during runtime - the mmap will be silently rebuild if there is a change in the numpy array size/shape/dtype.

Small Example Code:

import numpy as np
from ndsharray import NdShArray
    
shared_array = NdShArray("my_unique_tag", r_w='w')  # r_w must be specified

my_array = np.random.random((400, 800))
shared_array.write(my_array)

print(my_array)

That's all for writing into shared memory. How to read? Open a second python instance:

import numpy as np
from ndsharray import NdShArray

shared_array = NdShArray("my_unique_tag", r_w='r')  # r_w must be specified

status, my_array = shared_array.read()

print(my_array)

Documentation

Can be found here: https://ndsharray.readthedocs.io/en/latest/

Requirements

  • Python ≥ 3.6
  • numpy

Tested with example codes on

  • Windows 10, amd64, Python 3.6 / 3.8
  • Ubuntu 20, amd64, Python 3.6 /3.8
  • NVIDIA Jetson Nano with Ubuntu 18.04, ARM64-bit (aarch64), Python 3.6

Some technical notes

This library shall be an easy-to-use library and also shall be faster than pickling numpy arrays to another process. Please note that the python's provided shared_memory does the same as ndsharray, but is using byte array instead of numpy array! However, shared_memory is available since python 3.8 and not supported for python 3.6.

Installation from Github

Make sure to have git, python and pip in your environment path or activate your python environment.
To install enter in cmd/shell:

git clone https://github.com/monzelr/ndsharray.git

cd ndsharray

pip install .

Alternative with python:

python setup.py install

Metadata

Release files for ndsharray 1.1.4

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

Source distribution (sdist)

Source distribution for ndsharray 1.1.4
File Size Uploaded
ndsharray-1.1.4.tar.gz 12.0 kB Details

Built distribution (wheel)

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

Total release size: 20.7 kB

Release files / ndsharray-1.1.4.tar.gz

Download URL ndsharray-1.1.4.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9ce24a3e593dd1f9914ea8d9f44744cefae2e65da7e564dd93ec0f1a2d17d078
BLAKE2b-256 checksum
How to use checksums
6035aaa2dfd529e06cd46e50e8a2cf3ff48042ccd778c9996c880c5e49e0ca21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.12

Release files / ndsharray-1.1.4-py3-none-any.whl

Download URL ndsharray-1.1.4-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5993f45712db9681d7706ae27fa5fa53517eb09ea70d519818310b0b1c3a2187
BLAKE2b-256 checksum
How to use checksums
0bc6a5666e016d768b1d44a6603b31113f6d06f55c153ff237b4f5115ae92634
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.12

Release history Release notifications | RSS feed

This release

1.1.4 This release

2 release files

1.1.3

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.1

1 release file

1.0.0

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