Skip to main content

Python Basic EventEngine

Project description

PyEventEngine

High-performance, topic-driven event engine for Python with a Cython-accelerated core and a native Python fallback.

  • Fast publish/subscribe event routing by topic (exact + generic wildcard/pattern matching)
  • Clean, typed API with drop-in fallback when C extensions are unavailable
  • Built-in timers, handler stats (EventHookEx), and convenient formatting helpers

Installation

pip install PyEventEngine

Or install from source:

pip install git+https://github.com/BolunHan/PyEventEngine.git

Quick Start

import time

from event_engine import EventEngine, Topic, EventHook

# Create and start the engine
engine = EventEngine(capacity=8192)
engine.start()

# Register a handler for an exact topic
exact = Topic('Demo.Hello')

def hello_handler(name: str, topic=None):
    print(f"Hello {name} from {topic.value if topic else 'N/A'}")

engine.register_handler(exact, hello_handler)

# Publish a message
engine.put(exact, 'World')

# Clean up
time.sleep(0.1)
engine.stop()
engine.clear()

Generic topics (wildcards/patterns)

import time
from event_engine import Topic, EventEngine

engine = EventEngine()
pattern = Topic('Demo.{what}')

calls = []


def f(what: str, topic=None):
    calls.append((what, topic.value))


engine.register_handler(pattern, f)

engine.start()
engine.put(Topic('Demo.Test'), 'a test sub-topic')
engine.put(Topic('Demo.Live'), 'a live sub-topic')
time.sleep(0.1)  # allow some time for processing
engine.stop()

print(calls)  # [('a test sub-topic', 'Demo.Test'), ('a live sub-topic', 'Demo.Live')]

Timers (EventEngineEx)

from event_engine import EventEngine, EventEngineBase, EventEngine as EventEngineEx, Topic

engine = EventEngineEx(capacity=4096)
engine.start()

# Create a 1-second timer topic and subscribe
timer_topic = engine.get_timer(1.0)
engine.register_handler(timer_topic, lambda **kw: print('tick', kw))

# ... run a little while
import time; time.sleep(3)
engine.stop(); engine.clear()

Logging

By default, the package uses a colored logger under event_engine.base. To integrate with your application's logging, call set_logger once after import. It will propagate to submodules.

import logging
from event_engine import set_logger

logger = logging.getLogger('MyApp')
logger.setLevel(logging.INFO)
set_logger(logger)

Fallback behavior

On import, the package tries to use the Cython implementation (event_engine.capi). If that fails (e.g., no compiler available), it automatically falls back to the native Python implementation (event_engine.native). You can check the active backend via:

from event_engine import USING_FALLBACK
print('Using native fallback?' , USING_FALLBACK)

Development

  • Run unit tests and demos under demo/
  • Native performance test: python demo/native_performance_test.py
  • CAPI performance test (requires compiled extensions): python demo/capi_performance_test.py

Documentation

Full documentation is available at: https://bolunhan.github.io/PyEventEngine/ (auto-generated from main branch)

To build documentation locally, see docs/BUILD.md.


See demo/ for more examples: matching, timers, performance. Issues and PRs welcome!

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyeventengine-0.4.6.post1-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pyeventengine-0.4.6.post1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pyeventengine-0.4.6.post1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pyeventengine-0.4.6.post1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

File details

Details for the file pyeventengine-0.4.6.post1-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyeventengine-0.4.6.post1-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4c45dd09d858368735e2bb3a1f7413c48c5d15846d9d02d8fbf79e7084241f51
MD5 b9de66a3f9d04bf9feeffa1e24086251
BLAKE2b-256 2b64b90e3dd758fa15f3704c1bab04b4e873bfdce44cb5da636ded5a43803e81

See more details on using hashes here.

File details

Details for the file pyeventengine-0.4.6.post1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyeventengine-0.4.6.post1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bcb65819dfffc44e4bf0b93073a55e3fbf93de07470f870e7ecf287c38eff1fa
MD5 86c66b9c5cb9e1bc18bfae30e58e2414
BLAKE2b-256 052f432409df91f19383867acc2fdbeb95ff2b494af663e55694143bcd4206cc

See more details on using hashes here.

File details

Details for the file pyeventengine-0.4.6.post1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyeventengine-0.4.6.post1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6fa0e51bf0730db8d893d6f6d353253b3d6918292f48363e77c3987c552b685b
MD5 a1bcb8cb40677b72ad382b313b8653d7
BLAKE2b-256 67b213df1de0295dd40eff449daba3190f50692fc5119c16739121967f81e2db

See more details on using hashes here.

File details

Details for the file pyeventengine-0.4.6.post1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyeventengine-0.4.6.post1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2d82e7adc546a58928953c1eb6b5ff98ad8261da3b4a4b8a65e1ed2902f03125
MD5 89869416a11e4217b0582b60906549ff
BLAKE2b-256 3e5c0931174a9224f7af0c4a8b37236466aee22044bc435cb74b5c8c2595cace

See more details on using hashes here.

Supported by

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