EVNTDispatch


NameEVNTDispatch JSON
Version 0.0.2 PyPI version JSON
download
home_page
SummaryEVNTDispatch is a Python event system for seamless event-driven programming, offering flexibility and efficiency in handling and dispatching events.
upload_time2024-01-20 21:48:09
maintainer
docs_urlNone
authorCurtidor
requires_python
license
keywords evntdispatch event system event dispatcher event-driven programming synchronous events asynchronous events publish-subscribe developer tools python 3 cross-platform
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # EVNTDispatch

EVNTDispatch is a versatile Python library designed to facilitate event-driven programming by providing a flexible event dispatcher. Whether you are building a graphical user interface, a command-line application, or a complex system with asynchronous components, the Event System simplifies communication and coordination between different parts of your code.

## Key Features
* **Event Dispatching:** Easily define and dispatch events to notify components of changes or user interactions.

* **Asynchronous Support:** Seamlessly integrate asynchronous event listeners for efficient handling of time-consuming tasks without blocking the main execution.

* **Priority and Max Responders:** Control the order of event listener execution and limit the number of responders for fine-grained control over event handling.
 
* **Task Scheduling:** Schedule tasks to be executed after a specified delay, adding a layer of automation to your application.
## Basic Async Example

```python
import asyncio

from EVNTDispatch import EventDispatcher, PEvent, EventType

dispatcher = EventDispatcher()

# All event listeners must have a single parameter of type PEvent
async def process_message(event: PEvent):
    message_data, user_id = event.data
    
    # Simulate processing the message, e.g., storing it in a database or applying business logic
    print(f"Processing Message from User {user_id}: {message_data}")
    await asyncio.sleep(1)
    
    print("Message Processed")

async def send_message(user_id: int, message: str):
    # Trigger an event called 'new_message', notifying any listeners subscribed to 'new_message'
    await dispatcher.async_trigger(PEvent("new_message", EventType.Base, data=(message, user_id)))

async def main():
    # Start the event dispatcher
    dispatcher.start()
    
    # Subscribe 'process_message' to events called 'new_message'
    dispatcher.add_listener("new_message", process_message)

    # Tasks to simulate users sending messages
    tasks = [
        send_message(1, "Hello, how are you?"),
        send_message(2, "I'm doing well, thanks!"),
        send_message(1, "What's new?"),
        send_message(3, "Not much, just relaxing.")
    ]
    
    # Execute tasks concurrently
    await asyncio.gather(*tasks)
    
    # Close the dispatcher to wait for all tasks to finish
    await dispatcher.close()

if __name__ == "__main__":
    asyncio.run(main())
```

### License
This project is licensed under the MIT License.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "EVNTDispatch",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "EVNTDispatch,event system,event dispatcher,event-driven programming,synchronous events,asynchronous events,publish-subscribe,developer tools,Python 3,cross-platform",
    "author": "Curtidor",
    "author_email": "tannermatos18@gmai.com",
    "download_url": "",
    "platform": null,
    "description": "# EVNTDispatch\n\nEVNTDispatch is a versatile Python library designed to facilitate event-driven programming by providing a flexible event dispatcher. Whether you are building a graphical user interface, a command-line application, or a complex system with asynchronous components, the Event System simplifies communication and coordination between different parts of your code.\n\n## Key Features\n* **Event Dispatching:** Easily define and dispatch events to notify components of changes or user interactions.\n\n* **Asynchronous Support:** Seamlessly integrate asynchronous event listeners for efficient handling of time-consuming tasks without blocking the main execution.\n\n* **Priority and Max Responders:** Control the order of event listener execution and limit the number of responders for fine-grained control over event handling.\n \n* **Task Scheduling:** Schedule tasks to be executed after a specified delay, adding a layer of automation to your application.\n## Basic Async Example\n\n```python\nimport asyncio\n\nfrom EVNTDispatch import EventDispatcher, PEvent, EventType\n\ndispatcher = EventDispatcher()\n\n# All event listeners must have a single parameter of type PEvent\nasync def process_message(event: PEvent):\n    message_data, user_id = event.data\n    \n    # Simulate processing the message, e.g., storing it in a database or applying business logic\n    print(f\"Processing Message from User {user_id}: {message_data}\")\n    await asyncio.sleep(1)\n    \n    print(\"Message Processed\")\n\nasync def send_message(user_id: int, message: str):\n    # Trigger an event called 'new_message', notifying any listeners subscribed to 'new_message'\n    await dispatcher.async_trigger(PEvent(\"new_message\", EventType.Base, data=(message, user_id)))\n\nasync def main():\n    # Start the event dispatcher\n    dispatcher.start()\n    \n    # Subscribe 'process_message' to events called 'new_message'\n    dispatcher.add_listener(\"new_message\", process_message)\n\n    # Tasks to simulate users sending messages\n    tasks = [\n        send_message(1, \"Hello, how are you?\"),\n        send_message(2, \"I'm doing well, thanks!\"),\n        send_message(1, \"What's new?\"),\n        send_message(3, \"Not much, just relaxing.\")\n    ]\n    \n    # Execute tasks concurrently\n    await asyncio.gather(*tasks)\n    \n    # Close the dispatcher to wait for all tasks to finish\n    await dispatcher.close()\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n```\n\n### License\nThis project is licensed under the MIT License.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "EVNTDispatch is a Python event system for seamless event-driven programming, offering flexibility and efficiency in handling and dispatching events.",
    "version": "0.0.2",
    "project_urls": null,
    "split_keywords": [
        "evntdispatch",
        "event system",
        "event dispatcher",
        "event-driven programming",
        "synchronous events",
        "asynchronous events",
        "publish-subscribe",
        "developer tools",
        "python 3",
        "cross-platform"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "21ca259ef2aec2e7c090afefb3edd52e26d5e94d19878f97f543312bb4dea51e",
                "md5": "eaaa7329396a967be023a6770234997d",
                "sha256": "46322ffcca65d1a643c75a6e4cbcdee8841745b85c34b1a307561a5c5ce0fd63"
            },
            "downloads": -1,
            "filename": "EVNTDispatch-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "eaaa7329396a967be023a6770234997d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 15873,
            "upload_time": "2024-01-20T21:48:09",
            "upload_time_iso_8601": "2024-01-20T21:48:09.863330Z",
            "url": "https://files.pythonhosted.org/packages/21/ca/259ef2aec2e7c090afefb3edd52e26d5e94d19878f97f543312bb4dea51e/EVNTDispatch-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-20 21:48:09",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "evntdispatch"
}
        
Elapsed time: 0.18388s