Lightweight Python framework for writing clean and testable event-driven services
Project description
Dispytch is a lightweight, async Python framework for event-handling. It’s designed to streamline the development of clean and testable event-driven services.
🚀 Highlights
- 🔌 FastAPI-style dependency injection – clean, decoupled handlers
- 🧠 Async core – built for modern Python I/O
- 📬 Backend-flexible – with Kafka, RabbitMQ and Redis PubSub out-of-the-box
- 🧾 Pydantic-based validation – event schemas are validated using pydantic
- 🔁 Built-in retry logic – configurable, resilient, no boilerplate
📦 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, HandlerGroup
from service import UserService, get_user_service
class User(BaseModel):
id: str
email: str
name: str
class UserCreatedEvent(BaseModel):
user: User
timestamp: int
user_events = HandlerGroup()
@user_events.handler(topic='user_events', event='user_registered')
async def handle_user_registered(
event: Event[UserCreatedEvent],
user_service: Annotated[UserService, Dependency(get_user_service)]
):
user = event.body.user
timestamp = event.body.timestamp
print(f"[User Registered] {user.id} - {user.email} at {timestamp}")
await user_service.do_smth_with_the_user(event.body.user)
✨ Emitter example
import uuid
from datetime import datetime
from pydantic import BaseModel
from dispytch import EventBase
class User(BaseModel):
id: str
email: str
name: str
class UserEvent(EventBase):
__topic__ = "user_events"
class UserRegistered(UserEvent):
__event_type__ = "user_registered"
user: User
timestamp: int
async def example_emit(emitter):
await emitter.emit(
UserRegistered(
user=User(
id=str(uuid.uuid4()),
email="example@mail.com",
name="John Doe",
),
timestamp=int(datetime.now().timestamp()),
)
)
⚠️ Limitations
While dispytch is a great choice for most usecases there are some limitations to be aware of:
🧾 No schema-on-write support Dispytch uses a schema-on-read model. Formats like Avro, Protobuf, or Thrift aren’t supported yet.
🕵️ No dead-letter queue (DLQ) Failed messages are retried using built-in logic, but there’s no DLQ or fallback mechanism after final retries yet.
💡 See something missing? Some features aren’t here yet—but with your help, they could be. Contributions welcome via PRs or discussions.
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.10.1.tar.gz.
File metadata
- Download URL: dispytch-0.10.1.tar.gz
- Upload date:
- Size: 903.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e42946092daeb99a1dc64907e2ece7770ed93d96f1a8d14efe342f9d30d3661f
|
|
| MD5 |
d01f24af5f7f09c56c13af345e149cbd
|
|
| BLAKE2b-256 |
0945ff16fc14b1a5a80be735dad33f3e91bd91b9018683cf33041e48fdb6632b
|
File details
Details for the file dispytch-0.10.1-py3-none-any.whl.
File metadata
- Download URL: dispytch-0.10.1-py3-none-any.whl
- Upload date:
- Size: 25.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43804b778e20184745e0585296dec1637e96133e8df2c3a0e2a47b236339fdaf
|
|
| MD5 |
1d72a4f662eb37a0aa8bfa6d51a8609b
|
|
| BLAKE2b-256 |
807d68ad788501b4846652548b5d39bb4e53275f3e824128176930002a4ac21e
|