A Python library providing a robust, type-safe event system for game development and simulation.
Project description
Eventure
A Python library providing a robust, type-safe event system for game development and simulation. Eventure offers event tracking, time-based event management, and a powerful event bus with wildcard subscription support.
Features
- Event Class: Immutable events with tick, timestamp, type, and data attributes
- EventLog: Track, save, and replay sequences of events
- EventBus: Decouple event producers from consumers
- Wildcard Subscriptions: Subscribe to event patterns like
user.*or global* - JSON Serialization: Save and load events for persistence or network transmission
- Type Safety: Strong typing throughout the API
- Zero Dependencies: Pure Python implementation
Installation
# Using pip
pip install eventure
# Using uv
uv add eventure
Quick Start
from eventure import EventBus, EventLog, Event
# Create an event log to track game state
event_log = EventLog()
# Create an event bus connected to the log
event_bus = EventBus(event_log)
# Subscribe to specific events
def handle_user_created(event):
print(f"User created at tick {event.tick}: {event.data}")
unsubscribe = event_bus.subscribe("user.created", handle_user_created)
# Subscribe to all user events with wildcard
event_bus.subscribe("user.*", lambda event: print(f"User event: {event.type}"))
# Publish an event (automatically uses current tick from event_log)
event = event_bus.publish("user.created", {"id": 1, "name": "John"})
# Advance the game tick
event_log.advance_tick()
# Events can be serialized to JSON
json_str = event.to_json()
print(json_str)
# And deserialized back
reconstructed_event = Event.from_json(json_str)
# Save event history to file
event_log.save_to_file("game_events.json")
# Later, load event history
new_log = EventLog.load_from_file("game_events.json")
# Unsubscribe when done
unsubscribe()
Event System Architecture
Event
The Event class represents an immutable record of something that happened in your application:
@dataclass
class Event:
tick: int # Game tick when event occurred
timestamp: float # UTC timestamp
type: str # Event type identifier
data: Dict[str, Any] # Event-specific data
EventLog
The EventLog manages sequences of events and provides replay capability:
- Tracks current tick number
- Records events with timestamps
- Provides persistence through save/load methods
EventBus
The EventBus handles event publishing and subscription:
- Supports specific event type subscriptions
- Supports wildcard subscriptions (
user.*) - Supports global subscriptions (
*) - Automatically assigns current tick from EventLog
Development
# Clone the repository
git clone https://github.com/enricostara/eventure.git
cd eventure
# Install development dependencies
uv sync --all-extras
# Run tests
just test
License
MIT License - see LICENSE file for details
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 eventure-0.2.0.tar.gz.
File metadata
- Download URL: eventure-0.2.0.tar.gz
- Upload date:
- Size: 14.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ed25f4b3ea11aaad64095c1be328d8b5f9c8e3b945a218903b0241a6a5976a1
|
|
| MD5 |
057a357c107503755766589c8c7f6631
|
|
| BLAKE2b-256 |
e39c0ffb1ee46d281b62c4b66ffa58c2bf659387dcc375d125a18b9b8d18aab9
|
File details
Details for the file eventure-0.2.0-py3-none-any.whl.
File metadata
- Download URL: eventure-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7dc69d9313cc07e32f9657eabfed3abeb7b6f98410b0130d982a00a0dab11bb
|
|
| MD5 |
17777c808eeacbfc9ae3acf6fb9a9112
|
|
| BLAKE2b-256 |
f3c8bdcc7d3711f7f19b60685dc0e5a3be14c17b937a5fba2aa8e1a3649caf8c
|