Skip to content

eyueldk/unboil-events

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

unboil-events

Lightweight, strongly-typed event library for Python.

Installation

pip install unboil-events

Quick Start

from 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")

API

  • SyncEvent[P] - register callables Callable[P, None], invoke synchronously
  • AsyncEvent[P] - register Callable[P, Awaitable[None]], invoke with ainvoke or ginvoke
  • BaseEvent[P] - Base class, return type is always None.

Contributing

Pull requests welcome. Please run tests and follow code style.

License

MIT

About

Lightweight, strongly-typed event and signal library for Python.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages