Asynchronous named events with no dependencies
Project description
AsyncEv: asynchronous event objects
AsyncEv leverages asyncio to create events that can be subscribed to and waited for.
Installation
pip install asyncev
Usage
import asyncio
import asyncev
from dataclasses import dataclass
# Create an event
@dataclass
class MyEvent(asyncev.Event):
value: str
# Create a listener
async def on_myevent(ev: MyEvent):
print(f"Got a MyEvent with the value {ev.value}!")
# also works for methods, with binds possible at init time.
class Listener:
def __init__(self, name: str):
self.name = name
asyncev.bind(MyEvent, self.on_myevent)
async def on_myevent(self, ev: MyEvent):
print(f"{self.name} got a MyEvent with the value {ev.value}!")
asyncev.bind(MyEvent, on_myevent)
# Emit event (requires a running asyncio event loop)
async def main():
jeff = Listener("Jeff")
asyncev.emit(MyEvent(value="hello"))
await asyncio.sleep(.1)
del jeff # cleanup of event listeners is automatic
asyncev.emit(MyEvent("goodbye"))
await asyncio.sleep(.1)
asyncio.run(main())
Development
Recommended tooling is uv. install it with pip.
Building
$ uv build
Testing
$ uv run tox
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
asyncev-1.0.2.tar.gz
(18.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file asyncev-1.0.2.tar.gz.
File metadata
- Download URL: asyncev-1.0.2.tar.gz
- Upload date:
- Size: 18.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f866f56f3b22e4739df06dd50d0f46ed94d61924a0668841b0b4481ce1f1392
|
|
| MD5 |
a0075a0fa34dbb03370349ad5b395cf9
|
|
| BLAKE2b-256 |
be5d0cda8079dd83203587176733a8528acab529f335b16ee20caade78e6613b
|
File details
Details for the file asyncev-1.0.2-py3-none-any.whl.
File metadata
- Download URL: asyncev-1.0.2-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c5829327b024c154af9443cdfb0dd2f6eeabb105754be43250b5b719eb442b6
|
|
| MD5 |
b850a9743fb98e888f190d08e039d1b8
|
|
| BLAKE2b-256 |
e35e15992a341ebebd97bfb33507158a75a2414333f69c3af60ed57352a8ea24
|