Skip to main content

ZeroMQ Distributed EventBus for Python

Project description

ChimeraPy/aiodistbus

A Distributed Eventbus using ZeroMQ and AsyncIO for Python.

Test Coverage Status

The objective of this library is to provide both a local and distributed eventbus that are compatible to communicate. A similar API can be used in both versions of the eventbuses implementations.

Installation

For installing the package, download from PyPI and install with pip:

pip install aiodistbus

Here is a link to the Documentation. If you encounter any issues in terms of code or documentation, please don't hesitate to make an issue.

EventBus Example

The eventbus implementation follows a client-server design approach, with the DEventBus as the server and DEntryPoint as the client. Here is a quick example to emit an event.

import asyncio
from dataclasses import dataclass
from dataclasses_json import DataClassJsonMixin # DO NOT FORGET THIS!

import aiodistbus as adb

@dataclass
class ExampleEvent(DataClassJsonMixin): # NEEDS TO BE A DataClassJsonMixin!
    msg: str


async def handler(event: ExampleEvent):
    print(event)


async def main():
    # Create resources
    bus, e1, e2 = adb.DEventBus(), adb.DEntryPoint(), adb.DEntryPoint()

    # Connect
    await e1.connect(bus.ip, bus.port)
    await e2.connect(bus.ip, bus.port)

    # Add funcs
    await e1.on("test", handler, ExampleEvent)

    # Send message
    await e2.emit("test", ExampleEvent("hello"))

    # Flush
    await bus.flush()

    # Close resources
    await e1.close()
    await e2.close()
    await bus.close()

if __name__ == '__main__':
    asyncio.run(main())

Design

In the aiodistbus library, we provided 2 eventbus implementations: EventBus and DEventBus. The EventBus class is for local (within same Python runtime) observer pattern. In the other hand, DEventBus class is for a distributed eventbus that leverages ZeroMQ -- closing following the Clone pattern.

The Clone pattern uses a client-server structure, where a centralized broker broadcasts messages sent by clients. As described in the ZeroMQ Guide, this creates a single point of failure, but yields in a simpler and more scalable implementation.

Contributing

Contributions are welcomed! Our Developer Documentation should provide more details in how ChimeraPy works and what is in current development.

License

ChimeraPy and ChimeraPy/aiodistbus uses the GNU GENERAL PUBLIC LICENSE, as found in LICENSE file.

Funding Info

This project is supported by the National Science Foundation under AI Institute Grant No. DRL-2112635.

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

aiodistbus-0.0.2.tar.gz (33.4 kB view details)

Uploaded Source

Built Distribution

aiodistbus-0.0.2-py3-none-any.whl (42.0 kB view details)

Uploaded Python 3

File details

Details for the file aiodistbus-0.0.2.tar.gz.

File metadata

  • Download URL: aiodistbus-0.0.2.tar.gz
  • Upload date:
  • Size: 33.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for aiodistbus-0.0.2.tar.gz
Algorithm Hash digest
SHA256 1487e7416438b46c3855937eb59967c4943abfe3f26ff805c7f8e3d0e69a8bb4
MD5 33be1a6f1927e12301dd503cfa5eaa68
BLAKE2b-256 3fc6b9898aa21ca2fcc1a5a8e1108f1e553b6f28e26ac3772b01ee9a18aecb49

See more details on using hashes here.

File details

Details for the file aiodistbus-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: aiodistbus-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 42.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for aiodistbus-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b768335b100d71ac9ed16f4a24ee2659bf9342bd75451bdce4450bff5eba5b6c
MD5 760e49824d7c28cf7d5869adda580bf9
BLAKE2b-256 54b4e5b5a16d292a6a791aa7b1f756f19ecf540209d5ea994a7ccd7a46d6f2b4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page