Skip to main content

一个现代的事件系统

Project description

EventGraph

EventGraph 是一个现代的事件系统,旨在为 Python 应用提供高效、灵活的事件处理机制。

特性

  • 类型安全:利用 Python 的类型提示来确保事件处理的安全性。
  • 异步支持:原生支持异步事件处理。
  • 易于扩展:面向接口编程,易于扩展新的事件处理器。
  • 上下文切换:支持上下文切换,方便在事件处理中传递数据。
  • 消息队列:支持消息队列,意味着可以跨进程、跨机器进行事件处理。

快速开始

安装

使用 pip 安装 EventGraph:

pip install eventgraph>=0.1.0rc6

基本用法

  1. 初始化事件图:
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)
  1. 定义事件处理函数:
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")
  1. 定义参数处理器:
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)
  1. 发布和执行事件:
async def mian():
    g.start()
    g.postEvent(1) # 发布事件
    g.postEvent(Ts(2))
    await g.execute(Ts(1)) # 直接执行事件
    await asyncio.sleep(1)

asyncio.run(mian())

鸣谢

没有它们的存在就没有这个项目

项目灵感

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

eventgraph-0.1.0rc6.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

eventgraph-0.1.0rc6-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file eventgraph-0.1.0rc6.tar.gz.

File metadata

  • Download URL: eventgraph-0.1.0rc6.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.18.1 CPython/3.10.12 Linux/6.5.0-1025-azure

File hashes

Hashes for eventgraph-0.1.0rc6.tar.gz
Algorithm Hash digest
SHA256 6273321b0b46594a1b84ee1e311fd56ec85b35087aad9d5a636be17b59c72e45
MD5 3fa68c878f85d8064b086bb401ef3690
BLAKE2b-256 5681743c9c63cff2ca22393e62644dabe292021cd9988ac12e9a2a1e9cb8e396

See more details on using hashes here.

File details

Details for the file eventgraph-0.1.0rc6-py3-none-any.whl.

File metadata

  • Download URL: eventgraph-0.1.0rc6-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.18.1 CPython/3.10.12 Linux/6.5.0-1025-azure

File hashes

Hashes for eventgraph-0.1.0rc6-py3-none-any.whl
Algorithm Hash digest
SHA256 53701f8224f26f62650f853f414e6fd1aff97c203ec75e5c6194e75a51a6e469
MD5 5c35963d714ba7e18c283bbbcb0168bd
BLAKE2b-256 dd8f527d6b9bd13162923a3502be15afccb1f932e5614a9411caba3bc2343ab5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page