Skip to main content

Synaptic IPC

This project implements inter-process communication (IPC) using various protocols, including Zenoh.

Installation

To install Synaptic and its dependencies, run:

pip install synaptic

Subclassing IPC and Configuring Serializers

Subclassing IPC

To create a custom IPC implementation:

  1. Import the necessary modules:

    from synaptic.ipc.base import IPC, IPCConfig
    
  2. Create a new class that inherits from IPC:

    class CustomIPC(IPC):
        def __init__(self, config: IPCConfig):
            super().__init__(config)
            # Add any custom initialization here
    
        def initialize(self) -> None:
            # Implement initialization logic
    
        def cleanup(self) -> None:
            # Implement cleanup logic
    
        def get(self, key, value) -> Dict:
            # Implement get logic
    
        def put(self, key, value) -> None:
            # Implement put logic
    
        def update(self, values: dict) -> None:
            # Implement update logic
    
        def delete(self, key) -> None:
            # Implement delete logic
    

Configuring a Serializer

To configure a serializer for your IPC:

  1. Import the Serializer base class:

    from synaptic.serialization.base import Serializer
    
  2. Create a custom serializer:

    class CustomSerializer(Serializer):
        def tobytes(self, data):
            # Implement serialization logic
    
        def frombytes(self, data):
            # Implement deserialization logic
    
  3. Use the serializer in your IPC configuration:

    from synaptic.ipc.base import IPCConfig
    
    config = IPCConfig(
        serialization_protocol="custom",
        communication_protocol="your_protocol",
        # Other configuration options
    )
    custom_ipc = CustomIPC(config)
    custom_ipc.serializer = CustomSerializer()
    

Using Multiprocessing Manager

For more detailed information on multiprocessing and managers, refer to the Python multiprocessing documentation.

Example Usage

Here's an example of how to use the ZenohProtocol with msgpack serialization:

from synaptic.ipc.base import IPCConfig
from synaptic.synapse import State
# Configure Zenoh with msgpack serialization
config = IPCConfig(
    serialization_protocol="json",
    communication_protocol="zenoh",
    messaging_config=ZenohConfig(
        mode="peer",
        connect=[{"tcp": "localhost:7447"}],
        zenoh_key="example/state",
    )
)

with State(config) as state:
    # Put a state
    state.any_attribute = "Hello, World!"
    state.another_attribute = 42

    with State(config) as same_state:
        assert same_state.any_attribute == "Hello, World!"
        assert same_state.another_attribute == 42
            

Now For A Fun Example

from synaptic.synapse import State, IPCConfig
import asyncio

config = IPCConfig(
        serialization_protocol="json",
        communication_protocol="zenoh",
        messaging_config=ZenohConfig(
            mode="peer",
            connect=[{"tcp": "localhost:7447"}],
            zenoh_key="example/state",
        )
    )

async def main():
    async with State(config) as state:
        state.any_attribute = "Hello, World!"
        state.another_attribute = 42

        async with State(config) as same_state:
            async for i in range(10):
                same_state.incrementing_attribute = i
                await asyncio.sleep(1)
        
        async for i in range(10):
            print(state.incrementing_attribute)
            await asyncio.sleep(1)

asyncio.run(main())

Metadata

Release files for synaptic 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for synaptic 0.0.7
File Size Uploaded Provenance Actions
synaptic-0.0.7.tar.gz 854.4 kB Without provenance Details for synaptic-0.0.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for synaptic 0.0.7
File Interpreter ABI Platform Actions
synaptic-0.0.7-py3-none-any.whl Python 3 none any Details for synaptic-0.0.7-py3-none-any.whl

Total release size: 2.1 MB

Release files / synaptic-0.0.7.tar.gz

Download URL synaptic-0.0.7.tar.gz
Size 854.4 kB
Tags Source
SHA-256 checksum
How to use checksums
15d84a55ff1bb57cb21d7dc886d87871da6e26932f6bc80ac1fd278372b82828
BLAKE2b-256 checksum
How to use checksums
05147c3f241f33e2a988e5728a830cdf9004e5291a0cd587798ac87f11a369d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.10

Release files / synaptic-0.0.7-py3-none-any.whl

Download URL synaptic-0.0.7-py3-none-any.whl
Size 1.2 MB
Tags Python 3
SHA-256 checksum
How to use checksums
2e699cd592cde490e4dfc0d0c8a2968263ee01174dee3e55df3ccda3cb6a2279
BLAKE2b-256 checksum
How to use checksums
34c26b5db1f1970e7f58da875cb4712d25ab97d6a95941801f7deb28cfb61996
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.10

Security for synaptic 0.0.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page