Skip to main content

Build type-safe, event-driven Python apps with zero boilerplate.

Project description

EventModel

PyPI version Python 3.14+ uv Ruff Pydantic v2 Tests Pytest

Documentation is available at docs.eventmodel.app

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, StopEvent

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.
@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.service()
async def send_welcome_email(event: SendWelcomeEmail) -> StopEvent:
    print(f"Sending email to {event.target_email} with body: {event.body}")
    return StopEvent()


app.publish(UserCreated(user_id=123, email="user@example.com"))
app.run()

Synchronous Handlers

EventModel is fully compatible with synchronous code. You can use standard def functions for your handlers instead of async def, and the framework will automatically execute them safely without blocking the main async event loop.

@app.service()
def sync_process_new_user(event: UserCreated) -> SendWelcomeEmail:
    print(f"Sync processing user: {event.user_id}")
    return SendWelcomeEmail(
        target_email=event.email, 
        body="Welcome from sync!"
    )

Core Concepts

  1. Self-Routing Events: By subclassing EventModel and specifying a topic, your data model intrinsically knows where it belongs on the message broker.
  2. 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.
  3. Implicit Emissions: Handlers return initialized event objects. The framework automatically intercepts these returns and publishes them to their respective topics.
  4. Clean Architecture: Domain functions remain entirely pure. They take an EventModel as input and return an EventModel as output—no broker logic mixed in.
  5. Modular Routing: The framework supports Service instances that can be merged into a master App via app.include().

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

python_eventmodel-0.0.0a3.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_eventmodel-0.0.0a3-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file python_eventmodel-0.0.0a3.tar.gz.

File metadata

  • Download URL: python_eventmodel-0.0.0a3.tar.gz
  • Upload date:
  • Size: 7.6 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

Hashes for python_eventmodel-0.0.0a3.tar.gz
Algorithm Hash digest
SHA256 22f174921d7b3ecdc7e3ab87bb0692a83d1c785e584e361bf9830aca46266018
MD5 ab2d96d394bc6989df5589dc61bfd3b6
BLAKE2b-256 adedfad8272304a8c2f014b1399631bf82fed9a9daf9aa47aaf2290e0f4ba1bc

See more details on using hashes here.

File details

Details for the file python_eventmodel-0.0.0a3-py3-none-any.whl.

File metadata

  • Download URL: python_eventmodel-0.0.0a3-py3-none-any.whl
  • Upload date:
  • Size: 11.3 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

Hashes for python_eventmodel-0.0.0a3-py3-none-any.whl
Algorithm Hash digest
SHA256 af9179f835cb3389e4bc33fb6f788fcd970b11995c7d45cd79b79ff925e5214e
MD5 cfa9a1124498c502870d262e53786c7a
BLAKE2b-256 f5809e1da47d803dd37122da8b30ef0e9cf95d714d65dfbb6449e6b5661ef14b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page