EventGraph
EventGraph 是一个现代的事件系统,旨在为 Python 应用提供高效、灵活的事件处理机制。
特性
- 类型安全:利用 Python 的类型提示来确保事件处理的安全性。
- 异步支持:原生支持异步事件处理。
- 易于扩展:面向接口编程,易于扩展新的事件处理器。
- 上下文切换:支持上下文切换,方便在事件处理中传递数据。
- 消息队列:支持消息队列,意味着可以跨进程、跨机器进行事件处理。
快速开始
安装
使用 pip 安装 EventGraph:
pip install eventgraph>=0.1.0rc6
基本用法
- 初始化事件图:
import asyncio
from eventgraph.core.core import EventGraph, init_event_graph
from eventgraph.dispatcher.base import Dispatcher
from eventgraph.exceptions import NoCatchArgs
g = init_event_graph(int)
- 定义事件处理函数:
class Ts(int): ...
@g.receiver(int)
async def test1(a: int, b: str, c=1):
print(locals(), "test1")
@g.receiver(Ts)
async def test2(a: Ts, b: str, c=1, d: Optional[EventGraph] = None):
print(locals(), "test2")
- 定义参数处理器:
class IntDispatcher(Dispatcher[EventGraph[int], int]):
@classmethod
async def catch(cls, interface):
if interface.annotation == str:
return "string"
raise NoCatchArgs
g.add_dispatcher(int, IntDispatcher)
- 发布和执行事件:
async def mian():
g.start()
g.postEvent(1) # 发布事件
g.postEvent(Ts(2))
await g.execute(Ts(1)) # 直接执行事件
await asyncio.sleep(1)
asyncio.run(mian())
init_event_graph(type_var) 如果 type_var 相同,返回的 EventGraph 实例天然具有同类型的所有
事件处理器与参数处理器。
鸣谢
没有它们的存在就没有这个项目
项目灵感
Metadata
Release files for eventgraph 0.1.1
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 |
|---|---|---|---|---|
| eventgraph-0.1.1.tar.gz | 8.0 kB | Without provenance | Details for eventgraph-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| eventgraph-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for eventgraph-0.1.1-py3-none-any.whl |
Total release size: 18.8 kB
Release files / eventgraph-0.1.1.tar.gz
| Download URL | eventgraph-0.1.1.tar.gz |
|---|---|
| Size | 8.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
91cf27083eb482da1596ae656d4b1913ff685e675c0acf1d9597718602e83d79
|
|
BLAKE2b-256 checksum How to use checksums |
d9398d518cfdeeff5748a3302bb5bd584e116d68488a76591ee775df3196cb85
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
pdm/2.20.0.post1 CPython/3.10.12 Linux/6.5.0-1025-azure
|
Release files / eventgraph-0.1.1-py3-none-any.whl
| Download URL | eventgraph-0.1.1-py3-none-any.whl |
|---|---|
| Size | 10.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
122fb7a55cf46246be5e3fe7735ea67ba521154d4a9b2ed0863c2f9da6e3532c
|
|
BLAKE2b-256 checksum How to use checksums |
bdef1c4d1e39e5bf3b5f8e9337d57bf10fcffb03407cd65eb05a4ce77bf1f761
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
pdm/2.20.0.post1 CPython/3.10.12 Linux/6.5.0-1025-azure
|
Security for eventgraph 0.1.1
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.