ZeroMQ Distributed EventBus for Python
Project description
A Distributed Eventbus using ZeroMQ and AsyncIO for Python.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file aiodistbus-0.0.1.tar.gz
.
File metadata
- Download URL: aiodistbus-0.0.1.tar.gz
- Upload date:
- Size: 33.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b81a566b3b18704512718836347b89e80ffebf668767d95a97db57783723f02 |
|
MD5 | e4fd1b5c8b6c4c1eb55150178cd0258e |
|
BLAKE2b-256 | a59563b23128e3493ed487a66543933e5bf6de9113714a200d1d3f1bcf4b06f1 |
File details
Details for the file aiodistbus-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: aiodistbus-0.0.1-py3-none-any.whl
- Upload date:
- Size: 41.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3db96e2ca7f14b0c58808c1b80bb802eff77b6f52609e0a0b83b301004753e5b |
|
MD5 | e67c876437f65e120fcb47df05ef4817 |
|
BLAKE2b-256 | fea68b18d2ce51b8ad4d14fda5aeafd70b35505130f120cb194a36a594dface3 |