-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding documentation using MkDocs and ReadTheDocs.
- Loading branch information
1 parent
9e3ff29
commit 149d1fb
Showing
15 changed files
with
141 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[bumpversion] | ||
current_version = 0.0.1 | ||
commit = True | ||
tag = True | ||
message = Bump to version `v{new_version}` | ||
tag_name = v{new_version} | ||
|
||
[bumpversion:file:aiodistbus/version.py] | ||
|
||
[bumpversion:file:pyproject.toml] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[run] | ||
parallel = True | ||
branch = True | ||
concurrency = multiprocessing,thread | ||
omit = | ||
test/* | ||
|
||
[report] | ||
# Regexes for lines to exclude from consideration | ||
exclude_lines = | ||
# Have to re-enable the standard pragma | ||
pragma: no cover | ||
|
||
# Don't complain if non-runnable code isn't run | ||
if __name__ == .__main__.: | ||
|
||
# Don't complain about uncovered code in tests that were supposed to fail | ||
@pytest.mark.xfail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
version: 2 | ||
|
||
formats: | ||
- htmlzip | ||
|
||
python: | ||
install: | ||
- requirements: docs/requirements.txt | ||
- method: pip | ||
path: . | ||
system_packages: true | ||
|
||
mkdocs: | ||
configuration: mkdocs.yml | ||
|
||
build: | ||
os: ubuntu-22.04 | ||
tools: | ||
python: "3.10" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,42 @@ | ||
# aiodistbus | ||
A Distributed Eventbus using ZeroMQ and asyncio | ||
![ChimeraPy/aiodistbus](https://github.com/ChimeraPy/aiodistbus/assets/40870026/306bff08-612c-4cc2-8354-e2407a4c9de1) | ||
<p align="center"> | ||
<em>A Distributed Eventbus using ZeroMQ and AsyncIO for Python.</em> | ||
</p> | ||
<p align="center"> | ||
<a href="https://github.com/ChimeraPy/aiodistbus/actions?query=workflow%3ATest" target="_blank"> | ||
<img src="https://github.com/ChimeraPy/aiodistbus/workflows/Test/badge.svg" alt="Test"> | ||
</a> | ||
|
||
# Installation | ||
<a href='https://coveralls.io/github/ChimeraPy/aiodistbus?branch=main'> | ||
<img src='https://coveralls.io/repos/github/ChimeraPy/aiodistbus/badge.svg?branch=main' alt='Coverage Status' /> | ||
</a> | ||
</p> | ||
|
||
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``: | ||
|
||
```bash | ||
pip install aiodistbus | ||
``` | ||
|
||
# Useage | ||
|
||
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](https://zguide.zeromq.org/docs/chapter5/). | ||
|
||
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. | ||
|
||
## Event Subscriptions | ||
|
||
The front-facing API of both ``(EventBus, EntryPoint)`` and ``(DEventBus, DEntryPoint)`` are identifical, but important differences need to be consider. For a distributed configuration, ensure that any emitted ``Event`` data is serializable -- this is not a requirement for local setup. | ||
## EventBus Example | ||
|
||
```python | ||
from dataclasses import dataclass | ||
from dataclasses_json import DataClassJsonMixin | ||
from aiodistbus import EntryPoint, EventBus # or DEntryPoint, DEventBus | ||
TODO | ||
|
||
@dataclass | ||
class ExampleEvent(DataClassJsonMixin): | ||
msg: str | ||
## Design | ||
|
||
async def handler(event: ExampleEvent): | ||
assert isinstance(event, ExampleEvent) | ||
logger.info(f"Received event {event}") | ||
|
||
# Create resources | ||
bus = EventBus() # of DEventBus for distributed eventbus | ||
e1, e2 = EntryPoint(), EntryPoint() # or DEntryPoint for distributed eventbus | ||
|
||
# Add handlers | ||
await e1.on('example', handler, ExampleEvent) | ||
|
||
# Connect | ||
await e1.connect(bus) | ||
await e2.connect(bus) | ||
|
||
# Send message and e1's handler is executed | ||
event = await e2.emit('example', ExampleEvent(msg="hello")) | ||
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](https://zguide.zeromq.org/docs/chapter5/). | ||
|
||
# Closing (order doesn't matter) | ||
await bus.close() | ||
await e1.close() | ||
await e2.close() | ||
``` | ||
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. | ||
|
||
## Bridge between Local and Distributed | ||
## Contributing | ||
Contributions are welcomed! Our [Developer Documentation](https://chimerapy.readthedocs.io/en/latest/developer/index.html) should provide more details in how ChimeraPy works and what is in current development. | ||
|
||
```python | ||
## License | ||
[ChimeraPy](https://github.com/ChimeraPy) and [ChimeraPy/Orchestrator](https://github.com/ChimeraPy/Orchestrator) uses the GNU GENERAL PUBLIC LICENSE, as found in [LICENSE](./LICENSE) file. | ||
|
||
``` | ||
## Funding Info | ||
This project is supported by the [National Science Foundation](https://www.nsf.gov/) under AI Institute Grant No. [DRL-2112635](https://www.nsf.gov/awardsearch/showAward?AWD_ID=2112635&HistoricalAwards=false). |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Local EventBus & EntryPoint | ||
|
||
The front-facing API of both ``(EventBus, EntryPoint)`` and ``(DEventBus, DEntryPoint)`` are identifical, but important differences need to be consider. For a distributed configuration, ensure that any emitted ``Event`` data is serializable -- this is not a requirement for local setup. | ||
|
||
```python | ||
from dataclasses import dataclass | ||
from dataclasses_json import DataClassJsonMixin | ||
from aiodistbus import EntryPoint, EventBus # or DEntryPoint, DEventBus | ||
|
||
@dataclass | ||
class ExampleEvent(DataClassJsonMixin): | ||
msg: str | ||
|
||
async def handler(event: ExampleEvent): | ||
assert isinstance(event, ExampleEvent) | ||
logger.info(f"Received event {event}") | ||
|
||
# Create resources | ||
bus = EventBus() # of DEventBus for distributed eventbus | ||
e1, e2 = EntryPoint(), EntryPoint() # or DEntryPoint for distributed eventbus | ||
|
||
# Add handlers | ||
await e1.on('example', handler, ExampleEvent) | ||
|
||
# Connect | ||
await e1.connect(bus) | ||
await e2.connect(bus) | ||
|
||
# Send message and e1's handler is executed | ||
event = await e2.emit('example', ExampleEvent(msg="hello")) | ||
|
||
# Closing (order doesn't matter) | ||
await bus.close() | ||
await e1.close() | ||
await e2.close() | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Distributed EventBus & DEntryPoint |
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{!README.md!} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mkdocs | ||
mkdocstrings[python] | ||
markdown-include |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
mkdocs | ||
mkdocstrings[python] | ||
markdown-include | ||
asyncio-atexit | ||
pyzmq | ||
dataclasses-json | ||
aioreactive | ||
winloop; sys_platform == 'win32' | ||
uvloop; sys_platform != 'win32' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
site_name: aiodistbus | ||
theme: | ||
name: readthedocs | ||
highlightjs: true | ||
plugins: | ||
- search | ||
- mkdocstrings: | ||
handlers: | ||
# See: https://mkdocstrings.github.io/python/usage/ | ||
python: | ||
options: | ||
docstring_style: sphinx | ||
markdown_extensions: | ||
- markdown_include.include: | ||
base_path: . | ||
- admonition |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters