Skip to main content

ALT-event-system

A lightweight, flexible publish-subscribe event system for Python applications.

PyPI version Python Support License: MIT

Overview

ALT-event-system provides a simple yet powerful event-driven architecture that enables loose coupling between components through an event bus pattern. Perfect for building reactive applications, plugin systems, or any scenario where you need decoupled communication.

Features

  • 🚀 Simple API - Easy to understand and use
  • 🎯 Type-safe - Full type hints for better IDE support
  • 🔌 Loose Coupling - Components communicate without direct dependencies
  • 🌟 Wildcard Subscriptions - Subscribe to all events with *
  • 📜 Event History - Track and query past events
  • 🛡️ Error Isolation - Handler errors don't affect other handlers
  • 🔍 Source Tracking - Optional source identification for events
  • ⚡ Zero Dependencies - Uses only Python standard library

Installation

pip install ALT-event-system

Quick Start

from alt_event_system import EventSystem

# Create an event system
events = EventSystem()

# Define a handler
def on_user_login(event):
    print(f"User {event.data['user_id']} logged in from {event.data['ip']}")

# Subscribe to events
events.subscribe("user.login", on_user_login)

# Emit events
events.emit("user.login", {"user_id": 123, "ip": "192.168.1.1"})

Advanced Usage

Wildcard Subscriptions

Subscribe to all events:

def log_all_events(event):
    print(f"[{event.timestamp}] {event.type}: {event.data}")

events.subscribe("*", log_all_events)

Event History

Track and query past events:

# Get recent events
history = events.get_history(limit=10)

# Filter by event type
login_events = events.get_history(event_type="user.login")

Error Handling

Handler errors are isolated:

def safe_handler(event):
    print("I still work even if others fail!")

events.subscribe("test.event", safe_handler)

API Reference

  • EventSystem() - Create a new event system
  • subscribe(event_type, handler) - Subscribe to events
  • emit(event_type, data, source=None) - Emit an event
  • get_history(event_type=None, limit=100) - Get event history
  • clear_history() - Clear event history
  • get_subscriber_count(event_type) - Count subscribers

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Author

Avi Layani - avilayani@gmail.com

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for ALT-event-system 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ALT-event-system 0.1.0
File Size Uploaded
alt_event_system-0.1.0.tar.gz 9.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ALT-event-system 0.1.0
File Interpreter ABI Platform
alt_event_system-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.9 kB

Release files / alt_event_system-0.1.0.tar.gz

Download URL alt_event_system-0.1.0.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
daae85186b7ef78335cf756932cc32bf6cc02a8e9bcd833007e3f4c88e867ae5
BLAKE2b-256 checksum
How to use checksums
95a4251c0339908ab558b13f57fa75f4fe259e73bf5c2509611678614d286c8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / alt_event_system-0.1.0-py3-none-any.whl

Download URL alt_event_system-0.1.0-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
de71ceea8c61f2278a6a44ad917772597f2589e4f0624939f2852d203f5f4fe3
BLAKE2b-256 checksum
How to use checksums
322ea426d0a9be74e62d9dc7b57aafab06654f872d89241f2fa88d06339a1431
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page