Python framework for writing clean and testable event-driven services
Project description
Dispytch is an asynchronous Python framework designed to streamline the development of event-driven services.
🚀 Features
- 🧠 Async core – built for modern Python I/O
- 🔌 FastAPI-style dependency injection – clean, decoupled handlers
- 📬 Pluggable transport layer – with Kafka, RabbitMQ and Redis PubSub out-of-the-box
- 🧾 Pydantic v2 validation – event schemas are validated using pydantic
- 🔁 Built-in retry logic – configurable, resilient, no boilerplate
- ✅ Automatic acknowledgement – events are acknowledged automatically
- ⚠️ Error Handling – handle failures and prevent message loss with DLQ
- ⚖️ Composable Middleware – set up logging, metrics, filtering, observability
💡 See something missing?
Some features aren’t here yet—but with your help, they could be. Contributions welcome via PRs or discussions.
📦 Installation
Install using uv with extras for your preferred backend:
for Kafka support:
uv add dispytch[kafka]
For RabbitMQ support:
uv add dispytch[rabbitmq]
For Redis support:
uv add dispytch[redis]
📚 Documentation
Full documentation is available:
👉 here
✨ Handler example
from typing import Annotated
from pydantic import BaseModel
from dispytch import Event, Dependency, Router
from dispytch.kafka import KafkaEventSubscription
from dispytch.middleware import Filter
# Service Dependency
class UserService:
def __init__(self):
self.users = []
async def do_smth_with_the_user(self, user):
print("Doing something with user", user)
self.users.append(user)
def get_user_service():
return UserService()
# Event Schemas
class User(BaseModel):
id: str
email: str
name: str
class UserCreatedEvent(BaseModel):
type: str
user: User
timestamp: int
# Event handler
user_events = Router()
@user_events.handler(
KafkaEventSubscription(topic="user_events"),
middlewares=[Filter(lambda ctx: ctx.event["type"] == "user_registered")]
)
async def handle_user_registered(
event: Event[UserCreatedEvent],
user_service: Annotated[UserService, Dependency(get_user_service)]
):
user = event.user
timestamp = event.timestamp
print(f"[User Registered] {user.id} - {user.email} at {timestamp}")
await user_service.do_smth_with_the_user(user)
✨ Emitter example
import uuid
from datetime import datetime
from pydantic import BaseModel
from dispytch import EventEmitter, EventBase
from dispytch.kafka import KafkaEventRoute
class User(BaseModel):
id: str
email: str
name: str
class UserEvent(EventBase):
__route__ = KafkaEventRoute(
topic="user_events"
)
class UserRegistered(UserEvent):
type: str = "user_registered"
user: User
timestamp: int
async def example_emit(emitter: EventEmitter):
await emitter.emit(
UserRegistered(
user=User(
id=str(uuid.uuid4()),
email="example@mail.com",
name="John Doe",
),
timestamp=int(datetime.now().timestamp()),
)
)
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 dispytch-0.11.0.tar.gz.
File metadata
- Download URL: dispytch-0.11.0.tar.gz
- Upload date:
- Size: 904.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae660ac439536f3798ea6839e6fd8c8c7ee3dea96eaef8d24703216a1bfd21f5
|
|
| MD5 |
83ae20833c9a8ede67dce778c16ba151
|
|
| BLAKE2b-256 |
36c37b604e00e42658f1c8335078448c42557bb88250291d4630db897840b7b7
|
File details
Details for the file dispytch-0.11.0-py3-none-any.whl.
File metadata
- Download URL: dispytch-0.11.0-py3-none-any.whl
- Upload date:
- Size: 32.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6e865f9f46f5bf7c4cb509dadd36f2b823783e1472a60a5d767a3b837283de7
|
|
| MD5 |
d7f3badb94bbbf33b671b3fa1fa73038
|
|
| BLAKE2b-256 |
aef685d8cc8a47ef999bb866b7fd1c933146404f85965363f5d7a15155179ffa
|