Skip to main content

Python containers using shared memory.

Reason this release was yanked:

broken ci

Project description

sharedbox

[!WARNING] This project is a work in progress; be patient or feel free to contribute.

Python inter-process shared containers leveraging the boost::interprocess library.

Installation

It is reccomended to install sharedbox in a virtual environment; for example using uv:

uv venv --python 3.10
.venv\Scripts\activate
uv pip install sharedbox

Quick Start

import multiprocessing as mp
from sharedbox import SharedDict

# Use in child processes
def worker(segment_name):
    d = SharedDict(segment_name, create=False)  # Connect to existing
    d["worker_data"] = "Hello from worker!"
    d.close()  # Close in child process

if __name__ == "__main__":
    # Create a shared dictionary
    d = SharedDict("my_segment", create=True, size=10*1024*1024)
    d["hello"] = "world"
    d["data"] = [1, 2, 3, 4, 5]

    # Start worker
    p = mp.Process(target=worker, args=("my_segment",))
    p.start()
    p.join()

    print(d["worker_data"])  # "Hello from worker!"
    d.close() # Close in the main process
    d.unlink()  # Unlink (free resources)

Initialization with Data

You can initialize SharedDict with existing data for convenient setup:

import numpy as np
from sharedbox import SharedDict

# Initialize with mixed data types
config_data = {
    "app_name": "MyApp",
    "version": "1.0",
    "max_users": 1000,
    "features": ["auth", "logging"],
    "model_weights": np.array([0.1, 0.3, 0.6])
}

# Create SharedDict with initial data
shared_config = SharedDict("config", config_data, create=True)

# Data is immediately available
print(shared_config["app_name"])  # "MyApp"
print(shared_config["model_weights"])  # numpy array

# when a child process doesn't need the memory anymore call "close"
shared_config.close()

# the main process is in charge of cleaning up; call "unlink" to do so,
# similarly to a regular python SharedMemory object;
# make sure that the main process calls "close" before as well
shared_config.unlink()

Limitations

  • Nested dictionaries are "currently" unsupported
  • Project is quite unstable, might not provide great performance boost at this time
  • macOS unsupported

Examples

The examples/ folder contains some code examples on how to use the package.

Building locally

Requirements

  • git
  • uv
  • Python >= 3.10
  • vcpkg
  • CMake >= 3.15
  • A C++17 compatible compiler (MSVC on Windows, GCC on Linux)

[!NOTE] The build system automatically detects vcpkg and installed libraries through the VCPKG_ROOT environment variable. Make sure it's set before building.

Install and configure vcpkg

First, install and bootstrap vcpkg somewhere in your system.

Windows

# It is recommended to install in C:\
cd C:\
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
bootstrap-vcpkg.bat

# Set the VCPKG_ROOT environment variable (permanently)
setx VCPKG_ROOT "C:\vcpkg"

# Add vcpkg to your PATH (permanently)
setx PATH "%PATH%;C:\vcpkg"

Linux

You can use the install-vcpkg.sh script which will automatically install vcpkg in the /opt folder and set the VCPKG_ROOT environment variable. The script must be run with super user priviledges:

sudo bash install-vcpkg.sh

Install boost-interprocess

# From anywhere (vcpkg should be in PATH)
vcpkg install boost-interprocess

Build the package

Clone this repository and install using uv:

# Clone the repository
git clone https://github.com/jacopoabramo/sharedbox.git
cd sharedbox

# Create virtual environment and install in development mode
uv venv --python 3.10
uv pip install -e .[dev]

License

Licensed under Apache 2.0

sharedbox is built using the Boost C++ library, which is licensed under the Boost Software License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

sharedbox-0.2.2-cp310-cp310-win_amd64.whl (129.3 kB view details)

Uploaded CPython 3.10Windows x86-64

sharedbox-0.2.2-cp310-cp310-musllinux_1_2_x86_64.whl (597.3 kB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

sharedbox-0.2.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (136.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

File details

Details for the file sharedbox-0.2.2-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: sharedbox-0.2.2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 129.3 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sharedbox-0.2.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d7b441481086ccbdf2a56be442ffee943114a5fbd7b757b6222e9e9605867702
MD5 7659ffb46b1de9ffce78143af7f98e86
BLAKE2b-256 5ebff66be95166a5d68fe525535ec9ca5e5bbea30d2431cb4e614153e31790b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for sharedbox-0.2.2-cp310-cp310-win_amd64.whl:

Publisher: ci.yaml on jacopoabramo/sharedbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sharedbox-0.2.2-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for sharedbox-0.2.2-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 93d082cc458c6b69081ef28773ba1b56cc472166be598a60171124d429f4f009
MD5 86ca6ee22f4ac91166f0969e9b75007d
BLAKE2b-256 7954aa784c97914bcf174fe368291b58cca4d0320336db8456680fa3ce13777f

See more details on using hashes here.

Provenance

The following attestation bundles were made for sharedbox-0.2.2-cp310-cp310-musllinux_1_2_x86_64.whl:

Publisher: ci.yaml on jacopoabramo/sharedbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sharedbox-0.2.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for sharedbox-0.2.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bc0d28dd2d483f7a0102c3d179a827a362cdb9d1c96ebcde6696a3ecd56d6bb2
MD5 8ae890dab8c69e1f418908ef674055c1
BLAKE2b-256 fca6fc302e1168d78e4b91349c2249e78434a2f862d0352787c28751f9586bc3

See more details on using hashes here.

Provenance

The following attestation bundles were made for sharedbox-0.2.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: ci.yaml on jacopoabramo/sharedbox

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