Eventry
Eventry is a dependency-free Python library for asynchronous, in-process event routing and processing.
Eventry lets you create customizable routers for your own framework or application, or use the built-in default router for simpler use cases. It supports middleware and filters at every routing level: routers, handler managers, and individual handlers.
Installation
pip install eventry
Using built-in components
For simple use cases you can use built-in Dispatcher, DefaultRouter and DefaultHandlerManager.
from eventry.asyncio import Dispatcher, DefaultRouter, ExtendedEvent
router = DefaultRouter(name='my_router')
dp = Dispatcher(router)
# Let's create some custom event.
class MyEvent(ExtendedEvent, event_name='my_event'):
def __init__(self, trigger: str):
super().__init__()
self.trigger = trigger
# Default router has only one handler manager that does not filter events and accepts all of them.
# Type annotations don't filter events.
@router.on_event()
async def my_handler(event: ExtendedEvent) -> None:
print(event.__event_name__)
# If you want to filter events by type without creating custom routers, you can use handler filters.
@router.on_event(lambda event: event.name == 'my_event')
async def my_handler_with_filter(event: MyEvent):
print(event.trigger)
async def main():
my_event = MyEvent('qvvonk')
await dp.propagate_event(my_event) # both handlers will be executed.
event = ExtendedEvent()
await dp.propagate_event(event) # only `my_handler` will be executed.
if __name__ == '__main__':
import asyncio
asyncio.run(main())
Creating custom routers
Eventry lets you create your custom routers.
Note: unlike DefaultRouter, the base Router has no HandlerManager's or MiddlewareStorage's.
import asyncio
from eventry.asyncio import Router, DefaultHandlerManager, MiddlewareStorage, ExtendedEvent
class ApplicationRouter(Router):
def __init__(self, name: str = ''):
super().__init__(name=name)
self.on_new_message = self.add_handler_manager(
DefaultHandlerManager(name='on_message', event_filter='new_message')
)
self.on_new_order = self.add_handler_manager(
DefaultHandlerManager(name='on_order', event_filter='new_order')
)
@property
def outer_middleware(self) -> MiddlewareStorage:
return self.middleware.get_middlewares_storage('router.outer', raise_=True)
@property
def inner_middleware(self) -> MiddlewareStorage:
return self.middleware.get_middlewares_storage('router.inner', raise_=True)
# Now lets create our custom events.
class NewMessageEvent(ExtendedEvent, event_name='new_message'):
def __init__(self, message: str):
super().__init__()
self.message = message
class NewOrderEvent(ExtendedEvent, event_name='new_order'):
def __init__(self, order_id: int):
super().__init__()
self.order_id = order_id
# Now we can use new router and events in our application.
from eventry.asyncio import Dispatcher
router = ApplicationRouter(name='my_router')
dp = Dispatcher(router)
@router.on_new_message()
async def print_message(event: NewMessageEvent) -> None:
print(event.message)
@router.on_new_order()
async def print_order_id(event: NewOrderEvent) -> None:
print(event.order_id)
async def main():
await dp.propagate_event(NewMessageEvent('Hello World!'))
await dp.propagate_event(NewOrderEvent(12345))
if __name__ == '__main__':
asyncio.run(main())
Metadata
Release files for eventry 0.7.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| eventry-0.7.2.tar.gz | 20.0 kB | Without provenance | Details for eventry-0.7.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| eventry-0.7.2-py3-none-any.whl | Python 3 | none | any | Details for eventry-0.7.2-py3-none-any.whl |
Total release size: 44.8 kB
Release files / eventry-0.7.2.tar.gz
| Download URL | eventry-0.7.2.tar.gz |
|---|---|
| Size | 20.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5be33e374d5c9844ba264f01c71564c7187ffe0ab468ed979ec835ad10547b0d
|
|
BLAKE2b-256 checksum How to use checksums |
4b7039a52467c97d621f23538933f0d068a00423b4f1b1d49e89a66860ca00a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / eventry-0.7.2-py3-none-any.whl
| Download URL | eventry-0.7.2-py3-none-any.whl |
|---|---|
| Size | 24.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
27ffc79df8e21f6a85615a1c510fe7ddb016994f224d5cc98aec0f727db616ac
|
|
BLAKE2b-256 checksum How to use checksums |
6ea136123279128fda09aaf4aec24ebcddbdc482b87723ceb32d8b8c20ca5406
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for eventry 0.7.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.