Skip to content
jacopoabramoPublic

About

Python inter-process containers with shared memory backend.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

sharedbox

PyPI CI CodSpeed Ruff clang-format Checked with mypy

Warning

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

sharedbox keeps records in shared memory. Each box is one named segment, and every process that opens it reads and writes the same fields.

Installation

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

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

Quick start

import multiprocessing as mp
from typing import Annotated

from sharedbox import Capacity, SharedBox


class Motor(SharedBox):
    position: int
    enabled: bool
    label: Annotated[str, Capacity(32)]


def worker() -> None:
    motor = Motor.attach()          # finds the box by its class
    motor.position = 10
    motor.close()


if __name__ == "__main__":
    with Motor(1, False, "x-axis") as motor:
        motor.events.position.connect(lambda new, old: print(old, "->", new))
        child = mp.Process(target=worker)
        child.start()
        child.join()                      # prints: 1 -> 10
    Motor.unlink()

Documentation

The documentation site has a tutorial, how-to guides, explanations of how a box works, and the API reference.

C++ and C code can take a box from Python or open one by name; see the C and C++ guides.

License

Licensed under Apache 2.0

About

Python inter-process containers with shared memory backend.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages