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

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

  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.0a2.tar.gz (7.0 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.0a2-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

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

Hashes for python_eventmodel-0.0.0a2.tar.gz
Algorithm Hash digest
SHA256 5efef44319cdd355b3c2bd4ce507307c46873d09913834fc2251a9cb6b96cf8a
MD5 f7283dbe99e97f86952744192a587915
BLAKE2b-256 db97c55290bf96c73401ff693e00217459588b6206de8d00d4aaf73e0c9b753f

See more details on using hashes here.

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

Hashes for python_eventmodel-0.0.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 7c7303a1bfff51316c9f4788fa126ddfe9fe16fb08b26cdc8e25c134059ea45d
MD5 c54c635feae11198a87fa938918ca8e5
BLAKE2b-256 cb5fc6e86bcc2f682d3fee4109b7a7f197967b3270fc3d0ac181f65cb397635d

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