Name | asyncio-event-hub JSON |
Version |
1.1.0
JSON |
| download |
home_page | |
Summary | A library that provides users the ability to create event (loop) driven systems within the asyncio framework. |
upload_time | 2024-01-23 12:47:10 |
maintainer | |
docs_url | None |
author | David Hozic |
requires_python | >=3.8 |
license | |
keywords |
event
asyncio
event driven
event loop
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
============================================
Asyncio Event Hub
============================================
Asyncio Event Hub is a library that provides users with a way to easily create
event-driven applications within the asyncio framework. It provides one main class
``asyncio_event_hub.controller.EventController``, which can be used to emit events and add listeners (functions) to events
that get called from the event loop in the same order they were added.
Installation
==============
.. code-block:: bash
pip install asyncio-event-hub
Example
=============
.. code-block:: python
import asyncio_event_hub as aeh
import asyncio
# Create event controllers
main_controller = aeh.EventController()
sub_controller = aeh.EventController()
# Register sub_controller as a sub-controller of the main_controller
main_controller.add_subcontroller(sub_controller)
# Add listener via a decorator
@main_controller.listen("my_event")
async def listener1(a, b):
print(f"listener1({a}, {b})")
# Add listeners via a decorator
@main_controller.listen("my_event")
@sub_controller.listen("my_event")
def listener2(a, b):
print(f"listener2({a}, {b})")
async def stop(a):
main_controller.stop() # Stop main_controller and it's sub-controllers.
# Add listener through function
main_controller.add_listener("stop_event", stop, predicate=lambda a: a == 5) # Only call stop(a) if a is equal to 5
async def main():
main_controller.start() # Start main_controller and it's sub-controllers.
# Emit events into the event loop, executed asynchronously.
# listener1 is called once, listener2 is caller twice -
# once from main controller's event loop and once sub-controller's event loop. (not at this line, but asynchronously)
main_controller.emit("my_event", a=9, b =10)
# listener2 is called once from sub-controller's event loop. (not at this line, but asynchronously)
sub_controller.emit("my_event", a=1, b=2)
# await used to await for all listeners to finish processing event.
await main_controller.emit("stop_event", a=1) # Does not actually call anything since we have a predicate of a == 5.
await main_controller.emit("stop_event", a=5) # Stops controller asynchronously
asyncio.run(main())
Raw data
{
"_id": null,
"home_page": "",
"name": "asyncio-event-hub",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "event,asyncio,event driven,event loop",
"author": "David Hozic",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/6c/0a/a0571e9113db475f596245003b96f9cd9c5e1a7f5ed9654488d2ccc737ee/asyncio-event-hub-1.1.0.tar.gz",
"platform": null,
"description": "============================================\nAsyncio Event Hub\n============================================\n\nAsyncio Event Hub is a library that provides users with a way to easily create\nevent-driven applications within the asyncio framework. It provides one main class\n``asyncio_event_hub.controller.EventController``, which can be used to emit events and add listeners (functions) to events\nthat get called from the event loop in the same order they were added.\n\n\nInstallation\n==============\n.. code-block:: bash\n\n pip install asyncio-event-hub\n\n\nExample\n=============\n.. code-block:: python\n\n import asyncio_event_hub as aeh\n import asyncio\n\n\n # Create event controllers\n main_controller = aeh.EventController()\n sub_controller = aeh.EventController()\n\n # Register sub_controller as a sub-controller of the main_controller\n main_controller.add_subcontroller(sub_controller)\n\n\n # Add listener via a decorator\n @main_controller.listen(\"my_event\")\n async def listener1(a, b):\n print(f\"listener1({a}, {b})\")\n\n\n # Add listeners via a decorator\n @main_controller.listen(\"my_event\")\n @sub_controller.listen(\"my_event\")\n def listener2(a, b):\n print(f\"listener2({a}, {b})\")\n\n\n async def stop(a):\n main_controller.stop() # Stop main_controller and it's sub-controllers.\n\n\n # Add listener through function\n main_controller.add_listener(\"stop_event\", stop, predicate=lambda a: a == 5) # Only call stop(a) if a is equal to 5\n\n\n async def main():\n main_controller.start() # Start main_controller and it's sub-controllers.\n\n # Emit events into the event loop, executed asynchronously.\n # listener1 is called once, listener2 is caller twice -\n # once from main controller's event loop and once sub-controller's event loop. (not at this line, but asynchronously)\n main_controller.emit(\"my_event\", a=9, b =10)\n\n # listener2 is called once from sub-controller's event loop. (not at this line, but asynchronously)\n sub_controller.emit(\"my_event\", a=1, b=2)\n\n # await used to await for all listeners to finish processing event.\n await main_controller.emit(\"stop_event\", a=1) # Does not actually call anything since we have a predicate of a == 5.\n await main_controller.emit(\"stop_event\", a=5) # Stops controller asynchronously\n\n asyncio.run(main())\n",
"bugtrack_url": null,
"license": "",
"summary": "A library that provides users the ability to create event (loop) driven systems within the asyncio framework.",
"version": "1.1.0",
"project_urls": null,
"split_keywords": [
"event",
"asyncio",
"event driven",
"event loop"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1c4fe978277f6bc0ce241827c748f278309ebbcee743291b8a81d5cf51fb4cf7",
"md5": "9a749492a74ed7dc9d2ca49eaab3707e",
"sha256": "2ea5fb9036be183eb995eb9f4d6fe8055dc3dc938ed8cd8babe512725c814d17"
},
"downloads": -1,
"filename": "asyncio_event_hub-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9a749492a74ed7dc9d2ca49eaab3707e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 7435,
"upload_time": "2024-01-23T12:47:08",
"upload_time_iso_8601": "2024-01-23T12:47:08.498356Z",
"url": "https://files.pythonhosted.org/packages/1c/4f/e978277f6bc0ce241827c748f278309ebbcee743291b8a81d5cf51fb4cf7/asyncio_event_hub-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "6c0aa0571e9113db475f596245003b96f9cd9c5e1a7f5ed9654488d2ccc737ee",
"md5": "69bf5fceea0c626a3e1cb20083685d28",
"sha256": "85529543c0198f0e965fae2fbaa59d3bbc67ee2c175c54d87b5b67b661524274"
},
"downloads": -1,
"filename": "asyncio-event-hub-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "69bf5fceea0c626a3e1cb20083685d28",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 6937,
"upload_time": "2024-01-23T12:47:10",
"upload_time_iso_8601": "2024-01-23T12:47:10.046809Z",
"url": "https://files.pythonhosted.org/packages/6c/0a/a0571e9113db475f596245003b96f9cd9c5e1a7f5ed9654488d2ccc737ee/asyncio-event-hub-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-23 12:47:10",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "asyncio-event-hub"
}