Skip to main content

A Python framework for building event-driven applications with a clean publisher-subscriber pattern implementation.

Project description

EventsPype

CI codecov Python 3.13+ PyPI License: MIT Docs

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 MultiPublisher and MultiSubscriber
  • 🚀 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; Event is an optional base class. EventTag accepts enums, ints, or strings.

    • Event: Optional marker base class for event types
    • EventTag: Type alias for Enum | int | str
  • Publishers: Dispatch events to registered subscribers

    • EventPublisher: Single-publication publisher with weak-reference subscriber management
    • MultiPublisher: Multi-publication publisher; define EventPublication attributes as class variables
  • Subscribers: Receive and handle events

    • EventSubscriber: Abstract base class; override call(event, event_tag, caller)
    • OwnedEventSubscriber: Subscriber that holds a reference to an owner object
    • FunctionalEventSubscriber: Wraps a plain callable as a subscriber
    • MultiSubscriber: Define EventSubscription class attributes for declarative wiring
  • Subscriptions: Declarative wiring between publishers and subscribers

    • EventSubscription: Connects a MultiSubscriber method to a publisher's event tag
    • PublicationSubscription: Typed variant that wires directly to an EventPublication
  • Brokers: Pluggable event transport layer

    • MessageBroker: Abstract base class
    • LocalBroker: In-process dispatch (default behavior)
    • RedisBroker: Cross-process dispatch via Redis Pub/Sub
  • Utilities

    • TrackingEventSubscriber: Collects events and supports await wait_for(EventType)
    • ReportingEventSubscriber: Logs events via Python's logging module
    • EventVisualizer: 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


Download files

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

Source Distribution

eventspype-1.2.4.tar.gz (102.2 kB view details)

Uploaded Source

Built Distribution

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

eventspype-1.2.4-py3-none-any.whl (25.9 kB view details)

Uploaded Python 3

File details

Details for the file eventspype-1.2.4.tar.gz.

File metadata

  • Download URL: eventspype-1.2.4.tar.gz
  • Upload date:
  • Size: 102.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","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

Hashes for eventspype-1.2.4.tar.gz
Algorithm Hash digest
SHA256 c6990143c980b81f6c1b6e27b64731d9d3f953e0b1a773f087b1181af7ff2f95
MD5 e77a9a23a0d4cc19cfc268e44167c5ba
BLAKE2b-256 a2d8ebe0a6a37abcbfa3f4c3ff4e34cf2cc75ba6f52c1aa6f8fd7157445e5ada

See more details on using hashes here.

File details

Details for the file eventspype-1.2.4-py3-none-any.whl.

File metadata

  • Download URL: eventspype-1.2.4-py3-none-any.whl
  • Upload date:
  • Size: 25.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","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

Hashes for eventspype-1.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d24d900c7ebf4e46ca45bb54b65c1b1c6cc144821de13a9e71a4e6aa13a556c9
MD5 7ed2165350a7b06f0332cc0cbf106ec5
BLAKE2b-256 5924f2af063376b7b312d48be55fa03100939080ebdfcb637d877eeccac275e3

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