Lightweight, strongly-typed event library for Python.
pip install unboil-eventsfrom unboil_events import SyncEvent, AsyncEvent
import asyncio
# 1. SyncEvent: simple synchronous events
evt = SyncEvent[str]()
@evt
def on_msg(msg: str) -> None:
print(f"Received: {msg}")
evt.invoke("Hello")
# 2. AsyncEvent: async listeners
async_evt = AsyncEvent[str]()
@async_evt
async def on_async(msg: str) -> None:
await asyncio.sleep(0.1)
print(f"Async received: {msg}")
# Sequential execution
await async_evt.ainvoke("Hi")
# Parallel execution (asyncio.gather)
await async_evt.ginvoke("Parallel Hi")- SyncEvent[P] - register callables
Callable[P, None], invoke synchronously - AsyncEvent[P] - register
Callable[P, Awaitable[None]], invoke withainvokeorginvoke - BaseEvent[P] - Base class, return type is always
None.
Pull requests welcome. Please run tests and follow code style.
MIT