PyEventEngine
GitHub Actions: ⛔ temporarily disabled — kept disabled until the GitHub Actions issue is resolved. See
.github/workflows/README.md. CI runs on the GitLab mirror pipeline while disabled.
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
# From PyPI (pre-compiled wheels available)
pip install PyEventEngine
# From source (requires C compiler + Cython ≥ 3.0)
git clone https://github.com/BolunHan/PyEventEngine.git
cd PyEventEngine
# Build + install
./build.sh -i
# Or via Makefile:
make build && pip install -U . --no-build-isolation
# Or step by step:
python setup.py build_ext --inplace --verbose --force
pip install -U . --no-build-isolation
See the Installation Guide for platform-specific prerequisites, compile-time macros, and troubleshooting.
Quick Start
import time
from event_engine import EventEngine, Topic
# 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 time for processing
engine.stop()
print(calls) # [('a test sub-topic', 'Demo.Test'), ('a live sub-topic', 'Demo.Live')]
Timers (EventEngineEx)
import time
from event_engine import 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))
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 propagates 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). Check the active backend:
from event_engine import USING_FALLBACK
print('Using native fallback?', USING_FALLBACK)
Development
# Clone and build in-place
git clone https://github.com/BolunHan/PyEventEngine.git
cd PyEventEngine
./build.sh -i
# Run tests
python -m pytest demo/
# Performance benchmarks
python demo/native_performance_test.py
python demo/capi_performance_test.py # requires compiled extensions
Build scripts
| Command | Effect |
|---|---|
./build.sh -i |
Clean + build + install |
./build.sh -l |
List compile-time macros |
make build |
Clean + build in-place |
make clean-all |
Deep clean (removes .c/.so) |
Documentation
Full documentation: https://bolunhan.github.io/PyEventEngine/
Build locally:
pip install sphinx furo sphinx-autodoc-typehints
cd docs
sphinx-build -M html . _build
# Open _build/html/index.html
License
MIT — see LICENSE.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
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 pyeventengine-1.0.1-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pyeventengine-1.0.1-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 4.6 MB
- Tags: CPython 3.15t, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8492f2ed416f2aaa6495082f4a8522e6dbaac1cb758a61b44dec56ddb6bc942a
|
|
| MD5 |
6f39b77357e3ebfb8096b9ae4970c76e
|
|
| BLAKE2b-256 |
6a4c34e8ebc47464bcc0f2b6e5ad7ab6e76924f28cd5eaea5b7b08c5af9c3c7f
|
File details
Details for the file pyeventengine-1.0.1-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pyeventengine-1.0.1-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.15, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
648725024d6af7d468d140df54ae0feb06c871758616a60fdc3c6ad65502491d
|
|
| MD5 |
c2970e7cdeafd1f9ecdf443aa21701bd
|
|
| BLAKE2b-256 |
d252dfdf9ec076cdaa87145a20ae96beb3da11f5c3987f697f1fef64f4e946d7
|
File details
Details for the file pyeventengine-1.0.1-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pyeventengine-1.0.1-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 4.6 MB
- Tags: CPython 3.14t, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
678203d4fd88060cdfaea515ed50d4fc704592e4a3300667c847cfa658d9ddba
|
|
| MD5 |
d7bf31566487fb2054b272b04036eadb
|
|
| BLAKE2b-256 |
3529cb03ed3fc1a22421fcaa871e09847a00257ddec6ee865ab537860ce19e47
|
File details
Details for the file pyeventengine-1.0.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pyeventengine-1.0.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.14, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2bfa74a5508e5fe0844656531f3401666972989b051c6c4b943546ec25701b9
|
|
| MD5 |
9dd7fcb6ef71522f6c25e4d31f71c403
|
|
| BLAKE2b-256 |
6b77111ccaba4e1e282fc5088db4ef9a78617c2931fdd555f57aaf5b85c0f85d
|
File details
Details for the file pyeventengine-1.0.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pyeventengine-1.0.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 4.5 MB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5898f4f02a4e90c045218e55efecc9b22b0590fbacbae393d2811cc1f4659d3
|
|
| MD5 |
a11967ad6f57b0a4b048dcb1afa8e951
|
|
| BLAKE2b-256 |
f1140aac5b1d28c6b806804cd5614d58580a1470f4f5a37cb12af0e4e31b381c
|
File details
Details for the file pyeventengine-1.0.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pyeventengine-1.0.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 4.5 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ab04243e88bd254a244cb37745d5b36a2427a7a52848867d53ce593544e099b
|
|
| MD5 |
4bd370e585e545f31ead152716da85ac
|
|
| BLAKE2b-256 |
51f1b23396daaf2210e49d1dc23fc65687c5c95d7d50573c2e4e1e0a8d193290
|