Build type-safe, event-driven Python apps with zero boilerplate.
Project description
EventModel
Build type-safe, event-driven Python apps with zero boilerplate. Inspired by FastAPI and SQLModel, EventModel turns Pydantic classes into self-routing events. Just type-hint your inputs to subscribe and use return statements to emit. Pure, clean, and heavily typed.
Installation
uv add python-eventmodel
Quick Start
Define your events, type-hint your handlers, and let the framework handle the routing.
from eventmodel import App, EventModel
app = App()
users_app = App()
# 1. Define events with embedded routing metadata
class UserCreated(EventModel, topic="user.events.created"):
user_id: int
email: str
class SendWelcomeEmail(EventModel, topic="email.queue.outbound"):
target_email: str
body: str
# 2. Write pure domain logic.
# The input type dictates the subscription topic.
# The return type dictates the emission topic.
@users_app.service()
async def process_new_user(event: UserCreated) -> SendWelcomeEmail:
print(f"Processing new user: {event.user_id}")
return SendWelcomeEmail(
target_email=event.email,
body="Welcome!"
)
app.include(users_app)
Core Concepts
- Self-Routing Events: By subclassing
EventModeland specifying atopic, your data model intrinsically knows where it belongs on the message broker. - Implicit Subscriptions: Handlers use the
@service.service()decorator. The framework reads the type-hint of the input argument to determine which topic to subscribe to. - Implicit Emissions: Handlers return initialized event objects. The framework automatically intercepts these returns and publishes them to their respective topics.
- Clean Architecture: Domain functions remain entirely pure. They take an
EventModelas input and return anEventModelas output—no broker logic mixed in. - Modular Routing: The framework supports
Serviceinstances that can be merged into a masterAppviaapp.include().
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 python_eventmodel-0.0.0a2.tar.gz.
File metadata
- Download URL: python_eventmodel-0.0.0a2.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5efef44319cdd355b3c2bd4ce507307c46873d09913834fc2251a9cb6b96cf8a
|
|
| MD5 |
f7283dbe99e97f86952744192a587915
|
|
| BLAKE2b-256 |
db97c55290bf96c73401ff693e00217459588b6206de8d00d4aaf73e0c9b753f
|
File details
Details for the file python_eventmodel-0.0.0a2-py3-none-any.whl.
File metadata
- Download URL: python_eventmodel-0.0.0a2-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c7303a1bfff51316c9f4788fa126ddfe9fe16fb08b26cdc8e25c134059ea45d
|
|
| MD5 |
c54c635feae11198a87fa938918ca8e5
|
|
| BLAKE2b-256 |
cb5fc6e86bcc2f682d3fee4109b7a7f197967b3270fc3d0ac181f65cb397635d
|