Skip to main content

No project description provided

Project description

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())

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

synaptic-0.0.7.tar.gz (854.4 kB view details)

Uploaded Source

Built Distribution

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

synaptic-0.0.7-py3-none-any.whl (1.2 MB view details)

Uploaded Python 3

File details

Details for the file synaptic-0.0.7.tar.gz.

File metadata

  • Download URL: synaptic-0.0.7.tar.gz
  • Upload date:
  • Size: 854.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for synaptic-0.0.7.tar.gz
Algorithm Hash digest
SHA256 15d84a55ff1bb57cb21d7dc886d87871da6e26932f6bc80ac1fd278372b82828
MD5 be8a8caa8138d274fc2afb1123e88d5b
BLAKE2b-256 05147c3f241f33e2a988e5728a830cdf9004e5291a0cd587798ac87f11a369d6

See more details on using hashes here.

File details

Details for the file synaptic-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: synaptic-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for synaptic-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 2e699cd592cde490e4dfc0d0c8a2968263ee01174dee3e55df3ccda3cb6a2279
MD5 67aa80009e5393ad3dab29119c9dfa6b
BLAKE2b-256 34c26b5db1f1970e7f58da875cb4712d25ab97d6a95941801f7deb28cfb61996

See more details on using hashes here.

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