Skip to content

Commit

Permalink
Adding documentation using MkDocs and ReadTheDocs.
Browse files Browse the repository at this point in the history
  • Loading branch information
edavalosanaya committed Oct 30, 2023
1 parent 9e3ff29 commit 149d1fb
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 45 deletions.
10 changes: 10 additions & 0 deletions .bumpversion.cfg
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]
18 changes: 18 additions & 0 deletions .coveragerc
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
19 changes: 19 additions & 0 deletions .readthedocs.yml
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"
71 changes: 27 additions & 44 deletions README.md
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 added aiodistbus/version.py
Empty file.
Empty file added docs/bridging_eventbus.md
Empty file.
36 changes: 36 additions & 0 deletions docs/bus_examples.md
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()
```
1 change: 1 addition & 0 deletions docs/dbus_examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Distributed EventBus & DEntryPoint
Empty file added docs/evented_dataclass.md
Empty file.
Binary file added docs/images/banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{!README.md!}
3 changes: 3 additions & 0 deletions docs/requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mkdocs
mkdocstrings[python]
markdown-include
9 changes: 9 additions & 0 deletions docs/requirements.txt
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'
16 changes: 16 additions & 0 deletions mkdocs.yml
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[project]
name = "aiodistbus"
version = "0.0.1"
description = "ZeroMQ Distributed EventBus: "
description = "ZeroMQ Distributed EventBus for Python"
authors = [
{name = "Eduardo Davalos", email="eduardo.davalos.anaya@vanderbilt.edu"},
{name = "Umesh Timalsina", email="umesh.timalsina@vanderbilt.edu"}
Expand Down

0 comments on commit 149d1fb

Please sign in to comment.