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.3-cp310-cp310-win_amd64.whl (129.3 kB view details)

Uploaded CPython 3.10Windows x86-64

sharedbox-0.2.3-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.3-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.3-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: sharedbox-0.2.3-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.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d34f3d119e487da4472ae9d9044fe58c7815474284766c556e71b9dd24f5de54
MD5 c61028aa6d6a165a27d9c76faba29abb
BLAKE2b-256 4dcc643448711a8190254c0d59ef171abb17b0277d4c255cc678569d1e767e71

See more details on using hashes here.

Provenance

The following attestation bundles were made for sharedbox-0.2.3-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.3-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for sharedbox-0.2.3-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ec282c49f8712722d73396a48bd0748e70c5979fc19a483722f9491752e3d78a
MD5 db681ed0ce4fc9ec1c9f52e664771696
BLAKE2b-256 181b5a1745e2ae7825a0249473a7daa360a1ad19f7b308f746169fb88fd841f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for sharedbox-0.2.3-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.3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for sharedbox-0.2.3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 958f125ded745d3b1f32c751f2d957d723c20754734be3fe49405acf778bd4a3
MD5 161d6b725b757fd5d068a4ac744b8af4
BLAKE2b-256 c1110bd5a33f50472f5f8b02f6f33c7a93f1d6371b8cd5123c45c04982f6ecdd

See more details on using hashes here.

Provenance

The following attestation bundles were made for sharedbox-0.2.3-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