Skip to main content

Python containers using shared memory.

Reason this release was yanked:

build failed on manylinux

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

Uploaded CPython 3.10Windows x86-64

sharedbox-0.2.0-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.0-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.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: sharedbox-0.2.0-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.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 bbfaddd1edc8c5861dc839bc266ace0d049cad49042fcaa09ff1d016bf081cbd
MD5 67acad7fccf6b738643583f6bcc30e19
BLAKE2b-256 edfed71dff1c56b4e0ed66cb8de4161817530610459f8fb353dea0a4ce4d57a7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for sharedbox-0.2.0-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8acf54f1963093f7e3fa88a444f1b8d599c6a81ea55602920efec348059df3e2
MD5 407fc6f20fcae5002da24b520b87483c
BLAKE2b-256 a133004927f31b07e9741442d62465a4d52922dd5f886180338aed049d8e1679

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for sharedbox-0.2.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 59772a869c48ea4dd1d554fadf15c0297df7c40ed78761fe5b28dd7ac0d79b7e
MD5 2629531033ce3eb425607238fb5b9da0
BLAKE2b-256 2438d8527a9d2748f79338fd5890680be5a7f62057b9c5e5ab3536c30551c876

See more details on using hashes here.

Provenance

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