Quickstart: build on the event runtime
If you're starting a new consumer, or don't mind adopting a small framework, pymidil's event runtime gives you retries, dead-lettering, and idempotency out of the box. Telemetry to Observatory comes along for free, and dashboard control is honored automatically.
Before you start
You'll need an API key scoped to telemetry. Any admin can create one under Organization settings → API Keys. Keep it secret and treat it like a password.
- 1Install the SDKpip install "pymidil[auth,aws]"
- 2Write a subscriberA subscriber is a class with a
handlemethod. RaiseRetryableEventErrorfor anything that should be retried. Any other exception sends the event straight to the dead-letter queue:from pymidil.event import EventSubscriberfrom pymidil.event.exceptions import RetryableEventErrorclass OrderSubscriber(EventSubscriber):async def handle(self, event) -> None:if upstream_busy():raise RetryableEventError("throttled") # redelivered with backoffawait process(event) # any other error → dead-lettered - 3Wire up a consumerCreate an
SQSConsumerpointed at your queue, attach telemetry, and subscribe your handler:Dashboard pause/throttle/drain is honored automatically for the built-in consumers, no extra code needed. See [Consumer control](/sdks/python/guides/consumer-control) for how it works.from pymidil.event import SQSConsumer, SQSConsumerEventConfig, TelemetryDispatchHookfrom pymidil.event.observability.sinks.http import HttpTelemetrySinkconsumer = SQSConsumer(SQSConsumerEventConfig(type="sqs",queue_url="https://sqs.us-east-1.amazonaws.com/123456789012/orders",dlq_url="https://sqs.us-east-1.amazonaws.com/123456789012/orders-dlq",))consumer.add_hook(TelemetryDispatchHook(HttpTelemetrySink("https://api.midil.io", api_key="mo_your_api_key"),source_service="orders-svc",broker="sqs",))consumer.subscribe(OrderSubscriber()) - 4Add idempotency (optional, recommended)Protect an event type from being processed twice on redelivery:See [Idempotency & duplicates](/sdks/python/guides/idempotency-and-duplicates) for keying your own events and for a Redis-backed store across multiple instances.from pymidil.event.idempotency import IdempotencyPolicy, InMemoryIdempotencyStoreconsumer.use_idempotency(IdempotencyPolicy(InMemoryIdempotencyStore()))
- 5Start the consumerawait consumer.start()
- 6Check the dashboardOpen Overview. Your first event should appear within moments.
If you'd rather manage several producers/consumers together with named routing instead of wiring
each one by hand, EventBus provides that orchestration on top of the same classes. See
Examples.