A minimal, internal Python library for decoupled event communication using channels and wildcard-capable handlers.
Project description
vaitty_eventbus
A minimal, internal Python library for decoupled event communication using channels and wildcard-capable handlers.
🚀 Features
- 🔌 Pluggable event channels (console, file, or custom)
- 🎯 Wildcard-matching event handlers (
user.*,*) - 🔁 Emits and triggers events independently
- 🧼 No third-party dependencies
- 🧩 Fully configurable via Python dict or environment variables
📦 Installation
To manually install the package, download the vaitty_eventbus-X.X.X-py3-none-any.whl file from the dist directory and run the following command:
pip install vaitty_eventbus-X.X.X-py3-none-any.whl
🛠 Configuration
You can configure vaitty_eventbus through a dictionary or environment variables:
- EVENTBUS_CHANNEL: Determines the channel type to use:
console,file,http, or a registered custom type. Default:console - EVENTBUS_FILE: For the
filechannel, the path to the log file. Default:events.log - EVENTBUS_HTTP_ENDPOINT: For the
httpchannel, the target HTTP endpoint. Default:http://example.com/events
Example using environment variables:
export EVENTBUS_CHANNEL=file
export EVENTBUS_FILE=/tmp/my-events.log
Example using a configuration dictionary:
from vaitty_eventbus import EventHandlerFactory
config = {
"EVENTBUS_CHANNEL": "http",
"EVENTBUS_HTTP_ENDPOINT": "http://api.my-events.com/ingest"
}
handler = EventHandlerFactory.from_config(config=config)
🌿 Usage
Here's a simple example demonstrating basic usage of vaitty_eventbus:
from typing import Any, Dict
from vaitty_eventbus import EventHandlerFactory, Event
def handle_all(payload: Dict[str, Any]):
print(f"[*] Received: {payload}")
def handle_user(payload: Dict[str, Any]):
print(f"[user.*] User event: {payload}")
def handle_login(payload: Dict[str, Any]):
print(f"[user.login] Specific login: {payload['user_id']}")
handler = EventHandlerFactory.from_config()
# Send an event using a configured channel
handler.emit("user.login", {"user_id": 42})
# Register event handlers for each topic or use wildcards
handler.on("*", handle_all)
handler.on("user.*", handle_user)
handler.on("user.login", handle_login)
# Receive an event (maybe some /events endpoint on your app)
event = Event("user.login", {"user_id": 42})
# Call all matched handlers
handler.trigger(event)
🔮 Extensibility
The library is designed to be easily extended:
- Add new
EventChannelsubclasses. - Register them with
EventHandlerFactory.register_channel. - Configure their behavior through the dictionary or environment variables.
This makes it simple to integrate vaitty_eventbus into diverse workflows and systems!
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
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 vaitty_eventbus-0.0.5.tar.gz.
File metadata
- Download URL: vaitty_eventbus-0.0.5.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9704e5054a4a9cd4dc8c9d1903d2105771bc47b0cc9d0c4a0ac98a50b6fbd24a
|
|
| MD5 |
920a24960ea19ab99556596eef84088f
|
|
| BLAKE2b-256 |
c9c962521dc222991a8d1e96e5f9b1d7c22f6f22be1e4410aefe4595c67f0c29
|
File details
Details for the file vaitty_eventbus-0.0.5-py3-none-any.whl.
File metadata
- Download URL: vaitty_eventbus-0.0.5-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c0e2e2b5c016401b9907da8a4c523ee399bdd3a5d025d6ddfa854ecf57bec6e
|
|
| MD5 |
3999c271ae619dc1a0b9a514b43601ea
|
|
| BLAKE2b-256 |
59c4f34dac64b3e96caa3e7e42e4396c4f0c48e7a74f3cc7a7d782e2482a806d
|