Skip to main content

Python containers using shared memory.

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 Distribution

sharedbox-0.2.4.tar.gz (75.1 kB view details)

Uploaded Source

Built Distributions

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

sharedbox-0.2.4-cp313-cp313-win_amd64.whl (128.5 kB view details)

Uploaded CPython 3.13Windows x86-64

sharedbox-0.2.4-cp313-cp313-musllinux_1_2_x86_64.whl (595.9 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

sharedbox-0.2.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (136.0 kB view details)

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

sharedbox-0.2.4-cp312-cp312-win_amd64.whl (128.6 kB view details)

Uploaded CPython 3.12Windows x86-64

sharedbox-0.2.4-cp312-cp312-musllinux_1_2_x86_64.whl (596.0 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

sharedbox-0.2.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (136.0 kB view details)

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

sharedbox-0.2.4-cp311-cp311-win_amd64.whl (129.1 kB view details)

Uploaded CPython 3.11Windows x86-64

sharedbox-0.2.4-cp311-cp311-musllinux_1_2_x86_64.whl (596.9 kB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

sharedbox-0.2.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (136.5 kB view details)

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

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

Uploaded CPython 3.10Windows x86-64

sharedbox-0.2.4-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.4-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.4.tar.gz.

File metadata

  • Download URL: sharedbox-0.2.4.tar.gz
  • Upload date:
  • Size: 75.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sharedbox-0.2.4.tar.gz
Algorithm Hash digest
SHA256 4536006145bf2016625575741e470dd069ae6c078960f0bd22b0eb9915cbf721
MD5 fded678de631c3c5b4e9458fa3b68e61
BLAKE2b-256 e19e07cd4e54ce0c66f15b10b2240c102d57c5d9eb00c109f802cf545caeb43b

See more details on using hashes here.

Provenance

The following attestation bundles were made for sharedbox-0.2.4.tar.gz:

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.4-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: sharedbox-0.2.4-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 128.5 kB
  • Tags: CPython 3.13, 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.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 138916bbffce5cabfb15f7e54842afc366c8e0b872eafe603ea2c914950a6662
MD5 3b1806260205e4c0248780768dc8a78a
BLAKE2b-256 d61c1d2bb82043963ca0b85fab430213ad5608ee14744150294889843b9a69b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for sharedbox-0.2.4-cp313-cp313-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.4-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for sharedbox-0.2.4-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 409c2a90cf2d382b07076865cfa0afd62fb86a332ba4d6fbecb5ffec3ba8865e
MD5 8649c5c175ebe299b4de194e1619add6
BLAKE2b-256 8477f55735dfef0a9b66eea80834f1464447fd2dddd3ebbb03297ecf3a747561

See more details on using hashes here.

Provenance

The following attestation bundles were made for sharedbox-0.2.4-cp313-cp313-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.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for sharedbox-0.2.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4e6e418572af35ea22317b88aaf23271fd94f54d8fab467987f2b457310b5fb4
MD5 96a8dffda38d75fd2a0db5fd57c1e2a4
BLAKE2b-256 d0b49b754cb8776511e20308f70180be224219a983f761cd277e09bd2b85e8ea

See more details on using hashes here.

Provenance

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

File details

Details for the file sharedbox-0.2.4-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: sharedbox-0.2.4-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 128.6 kB
  • Tags: CPython 3.12, 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.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6243e070a81dffbe4362b10de1d19efa7119e55f92b46f0c074d2566f62f9388
MD5 1e1b5eddd2f0781d2aa277d124e6a0bf
BLAKE2b-256 5f9e1b70fb581c2d71ee00d6c94584d92935d67ea673e0f784cbddbc739e21f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for sharedbox-0.2.4-cp312-cp312-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.4-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for sharedbox-0.2.4-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c788dab08c8892a8d4fd487acb9a5c47f0689f8d488eddf288e62099d9ac5095
MD5 d538f1087228c7698f7b244c9cf43564
BLAKE2b-256 59c598a8c74795d443f5e17439ef8dbd1cb60821cad3bd7859cf7bd2115ee284

See more details on using hashes here.

Provenance

The following attestation bundles were made for sharedbox-0.2.4-cp312-cp312-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.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for sharedbox-0.2.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 362b4ee0bf6735825cccfdfb246fffe4593e2919314f67d3dfedc2278c571271
MD5 3847880223b2ff83fa5cbc750ed6b670
BLAKE2b-256 3f8b3aa03a8e290d5f458e18d02dc8671849577cdb0308b465bfb0c1cf864667

See more details on using hashes here.

Provenance

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

File details

Details for the file sharedbox-0.2.4-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: sharedbox-0.2.4-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 129.1 kB
  • Tags: CPython 3.11, 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.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 55fef82c118809d278d1f82ac4b88c91afb2302e8918fe706485ebc834d1de0a
MD5 16c73a5e0300e8dd3e9f71960f58641f
BLAKE2b-256 4e1494299ac91963d3b6384605d848fc60538d7b920d0f7d497861d6815e9a68

See more details on using hashes here.

Provenance

The following attestation bundles were made for sharedbox-0.2.4-cp311-cp311-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.4-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for sharedbox-0.2.4-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c8f5e11a4f299727826bccde21d451f3996b44f7f6cff3cda7a78915a23c2f68
MD5 f15425c6206d2f2f696e08a2a0670720
BLAKE2b-256 77b1d1e58e292be8f2037634980dd43cf54ee92d58950bbe1d236ef46fd4d185

See more details on using hashes here.

Provenance

The following attestation bundles were made for sharedbox-0.2.4-cp311-cp311-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.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for sharedbox-0.2.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d5d339a1c45dda3d6e750ca4e8f8d72dd2c0fee537d0424b3bd52ee30ea60208
MD5 07cc8c7358c8642e371303afb421e6b6
BLAKE2b-256 9ac7efc8aa001cc88dc276b9c766cecb94f4cc5d6e5dd01c3cf9a72c643dead4

See more details on using hashes here.

Provenance

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

File details

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

File metadata

  • Download URL: sharedbox-0.2.4-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.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 543a23bc8085e4d57eace1251aba6154dbbdf424f6186056ac4c407097caba2f
MD5 70974d7c90813316aebe77498d2e85e0
BLAKE2b-256 f0bd354c4e0292ec99be8649c956306e8c346d358829e7bde56ba2c233e97a5e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for sharedbox-0.2.4-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9d543efbf02c1c1599cc4c4e28fb995b22b53f2fc167bad664539c3e378e618c
MD5 a11d0cd5a7f4b72620f135f3ebe0b6ab
BLAKE2b-256 0fd0b860fbfbf6fcdf18bf4fbac4383faa5927cab924069adb3ec9ad83de5fc8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for sharedbox-0.2.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d8105c676da1d384241477aa39916dc4d6df679acffc934384de3a74d35a9de8
MD5 10c38835e1ea037154b204142e3dd298
BLAKE2b-256 a8e75b070b7203a5ba4d1ae12321394276861c55ebff372cbe5d3983ccbe8875

See more details on using hashes here.

Provenance

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