Event handling stereotype for Spakky Framework (@EventHandler, @on_event)
Project description
Spakky Event
Event handling stereotype for Spakky Framework.
Installation
pip install spakky-event
Features
@EventHandler: Stereotype for event handler classes@on_event: Decorator for marking methods as event handlers- Type-safe: Full type hint support for event types
- Async support: Native async/await for event processing
Quick Start
Define Events
Events should extend AbstractDomainEvent from spakky-domain:
from dataclasses import dataclass
from spakky.domain.models.event import AbstractDomainEvent
@dataclass
class UserCreatedEvent(AbstractDomainEvent):
user_id: str
email: str
@dataclass
class UserDeletedEvent(AbstractDomainEvent):
user_id: str
Create Event Handler
Use @EventHandler stereotype with @on_event decorators:
from spakky.event.stereotype.event_handler import EventHandler, on_event
@EventHandler()
class UserEventHandler:
def __init__(self, notification_service: NotificationService) -> None:
self.notification_service = notification_service
@on_event(UserCreatedEvent)
async def on_user_created(self, event: UserCreatedEvent) -> None:
await self.notification_service.send_welcome_email(event.email)
@on_event(UserDeletedEvent)
async def on_user_deleted(self, event: UserDeletedEvent) -> None:
await self.notification_service.send_goodbye_email(event.user_id)
Integration with Message Brokers
The @EventHandler stereotype works with Spakky's message broker plugins:
RabbitMQ
pip install spakky-rabbitmq
from spakky.core.application.application import SpakkyApplication
from spakky.core.application.application_context import ApplicationContext
app = (
SpakkyApplication(ApplicationContext())
.load_plugins() # Loads spakky-rabbitmq plugin
.scan()
.start()
)
Kafka
pip install spakky-kafka
from spakky.core.application.application import SpakkyApplication
from spakky.core.application.application_context import ApplicationContext
app = (
SpakkyApplication(ApplicationContext())
.load_plugins() # Loads spakky-kafka plugin
.scan()
.start()
)
API Reference
Stereotypes
| Decorator | Description |
|---|---|
@EventHandler() |
Marks a class as an event handler (extends @Pod) |
@on_event(EventType) |
Marks a method as handler for specific event type |
Interfaces
| Class | Description |
|---|---|
IEventPublisher |
Sync event publisher interface |
IAsyncEventPublisher |
Async event publisher interface |
IEventConsumer |
Sync event consumer interface |
IAsyncEventConsumer |
Async event consumer interface |
Types
| Type | Description |
|---|---|
EventRoute |
Annotation class for event routing metadata |
DomainEventT |
Type variable bound to AbstractDomainEvent |
IEventHandlerCallback |
Type alias for event handler callbacks |
Errors
| Class | Description |
|---|---|
AbstractSpakkyEventError |
Base error for event operations |
DuplicateEventHandlerError |
Raised when duplicate handlers registered |
InvalidMessageError |
Raised when message is malformed |
Related Packages
| Package | Description |
|---|---|
spakky-domain |
DDD building blocks including AbstractDomainEvent |
spakky-rabbitmq |
RabbitMQ implementation of event publisher/consumer |
spakky-kafka |
Kafka implementation of event publisher/consumer |
License
MIT License
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 spakky_event-4.0.0.tar.gz.
File metadata
- Download URL: spakky_event-4.0.0.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3877e7632e06fb0a8b761e8b20814bd5e3fa92333549cc67d9dd4d352400b7d
|
|
| MD5 |
088cfb450bc7d2d0f6de8c67b406779f
|
|
| BLAKE2b-256 |
8610aaddbe1c608bb9a9ff5f4f94c214cf63a82d1cbea354779b5f7d451e2e20
|
Provenance
The following attestation bundles were made for spakky_event-4.0.0.tar.gz:
Publisher:
publish-package.yml on E5presso/spakky-framework
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spakky_event-4.0.0.tar.gz -
Subject digest:
e3877e7632e06fb0a8b761e8b20814bd5e3fa92333549cc67d9dd4d352400b7d - Sigstore transparency entry: 747178030
- Sigstore integration time:
-
Permalink:
E5presso/spakky-framework@7e704d30046c05c7308cc96ea564ae286da96a81 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/E5presso
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-package.yml@7e704d30046c05c7308cc96ea564ae286da96a81 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file spakky_event-4.0.0-py3-none-any.whl.
File metadata
- Download URL: spakky_event-4.0.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a19cd2331f1105ddf760951db3547a75ca7f36afaa265e6ddc14f6bedd5bbf05
|
|
| MD5 |
881949e504215dc196ae58af81f317c2
|
|
| BLAKE2b-256 |
e821f07617a07738fbd94714021ad601817ad286aa4bc12d09930ebcfa518756
|
Provenance
The following attestation bundles were made for spakky_event-4.0.0-py3-none-any.whl:
Publisher:
publish-package.yml on E5presso/spakky-framework
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spakky_event-4.0.0-py3-none-any.whl -
Subject digest:
a19cd2331f1105ddf760951db3547a75ca7f36afaa265e6ddc14f6bedd5bbf05 - Sigstore transparency entry: 747178033
- Sigstore integration time:
-
Permalink:
E5presso/spakky-framework@7e704d30046c05c7308cc96ea564ae286da96a81 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/E5presso
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-package.yml@7e704d30046c05c7308cc96ea564ae286da96a81 -
Trigger Event:
workflow_dispatch
-
Statement type: