A Python framework for building event-driven applications with a clean publisher-subscriber pattern implementation.
Project description
EventsPype
A lightweight, type-safe Python framework for building event-driven applications. EventsPype provides a clean publisher-subscriber pattern implementation with support for multiple event types, async waiting, message brokers, and architecture visualization.
Features
- 🎯 Type-Safe Events: Runtime type checking ensures events match their declared publication class
- 🔄 Multi-Publisher/Subscriber: Handle multiple event types with
MultiPublisherandMultiSubscriber - 🚀 Async Support: Await specific event types with
TrackingEventSubscriber.wait_for() - 🔌 Message Brokers: Swap between in-process (
LocalBroker) and Redis (RedisBroker) dispatch - 🛠️ Functional Subscribers: Register plain callbacks without subclassing
- 📊 Tracking & Reporting: Built-in subscribers for testing and structured logging
- 🖼️ Architecture Visualization: Generate graphviz diagrams of your event system
- 🔒 Memory Safe: Weak references prevent lapsed subscriber memory leaks
- 🧪 Well Tested: Comprehensive test suite with high coverage
Installation
# Using pip
pip install eventspype
# Using uv
uv add eventspype
Quick Start
from dataclasses import dataclass
from eventspype import EventPublisher, EventPublication, EventSubscriber
# Define an event type
@dataclass
class UserCreatedEvent:
user_id: int
username: str
# Create a publication and publisher
publication = EventPublication("user_created", UserCreatedEvent)
publisher = EventPublisher(publication)
# Create a subscriber
class UserHandler(EventSubscriber):
def call(self, event, event_tag, caller):
print(f"User created: {event.username} (ID: {event.user_id})")
# Subscribe and publish
handler = UserHandler()
publisher.add_subscriber(handler)
publisher.publish(UserCreatedEvent(user_id=1, username="alice"))
Core Components
-
Events: Any Python object;
Eventis an optional base class.EventTagaccepts enums, ints, or strings.Event: Optional marker base class for event typesEventTag: Type alias forEnum | int | str
-
Publishers: Dispatch events to registered subscribers
EventPublisher: Single-publication publisher with weak-reference subscriber managementMultiPublisher: Multi-publication publisher; defineEventPublicationattributes as class variables
-
Subscribers: Receive and handle events
EventSubscriber: Abstract base class; overridecall(event, event_tag, caller)OwnedEventSubscriber: Subscriber that holds a reference to an owner objectFunctionalEventSubscriber: Wraps a plain callable as a subscriberMultiSubscriber: DefineEventSubscriptionclass attributes for declarative wiring
-
Subscriptions: Declarative wiring between publishers and subscribers
EventSubscription: Connects aMultiSubscribermethod to a publisher's event tagPublicationSubscription: Typed variant that wires directly to anEventPublication
-
Brokers: Pluggable event transport layer
MessageBroker: Abstract base classLocalBroker: In-process dispatch (default behavior)RedisBroker: Cross-process dispatch via Redis Pub/Sub
-
Utilities
TrackingEventSubscriber: Collects events and supportsawait wait_for(EventType)ReportingEventSubscriber: Logs events via Python'sloggingmoduleEventVisualizer: Generates graphviz architecture diagrams
Documentation
Full documentation is available at gianlucapagliara.github.io/eventspype.
Development
EventsPype uses uv for dependency management and packaging:
# Install dependencies
uv sync
# Run tests
uv run pytest
# Run type checks
uv run mypy eventspype
# Run linting
uv run ruff check .
# Run pre-commit hooks
uv run pre-commit run --all-files
Project details
Release history Release notifications | RSS feed
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 eventspype-1.1.0.tar.gz.
File metadata
- Download URL: eventspype-1.1.0.tar.gz
- Upload date:
- Size: 80.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c3a05892d68e06108962fd21d9d5bfc6f715ae4c8e9ea4b22ef7c747e7429ef
|
|
| MD5 |
94320fead712eb2fee8ee3407017a51d
|
|
| BLAKE2b-256 |
e3109f5d26876dd1dbbbb519c0ab912be0ee0ceb0ef55a37d17b0fd44c0b79f7
|
File details
Details for the file eventspype-1.1.0-py3-none-any.whl.
File metadata
- Download URL: eventspype-1.1.0-py3-none-any.whl
- Upload date:
- Size: 22.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b01897d5fb56c90b003f6876c2b79ee9674c2b0a6e9f958bda75ecc2c1fa2ff
|
|
| MD5 |
1048eef16416c365537320f9e74fc046
|
|
| BLAKE2b-256 |
da9f8d018f57a55e7cd6c055aa22c68d1498cc9f5b5d393ca7bc8dec3bf41cb1
|