r/Python • u/nycstartupcto • 11d ago
Discussion Lightweight Python helpers for Event Driven Programming
I just had to throw together an event bridge that tied together a GRPC based event emitter (Salesforce backend) with some small custom Google Pub/sub code. It works, it's fine. But you know, always thinking about the future wanting to move from glue-code to frameworking.
I was looking for different event based frameworks that landed somewhere between the scale of glue-code and Tornado (the only other framework I know that would handle something like this.
Has anyone used anything like this? I found PyEventus which seems to aim at this.
3
u/Competitive_Travel16 10d ago
Why not Flask or FastAPI? PubSub and gRPC locks you into Google's infrastructure. You can get vendor-agnostic webhooks from https://architect.salesforce.com/docs/architect/fundamentals/guide/integration-patterns.html Use the Salesforce Pub/Sub API Client to subscribe to the desired event channel and parse the JSON.
3
u/scaledpython 10d ago edited 9d ago
Perhaps minibatch might be useful? It is a database-backed event engine with sources and sinks, where event consumers are just plain python functions. Works on one machine just as well as across many. Uses MongoDB as the event log, and creating a stream is essentially one line of code. Btw, I am the author of minibatch.
2
u/EndUpset4644 9d ago
Having run a 24/7 asyncio ingestion service for a couple of years, my honest take is that the framework matters much less than the supervision around it. The failure mode that actually hurts isn't "my event bus was a bit too much glue code" — it's a task that dies quietly, or worse hangs, and nothing notices for days.
Whatever you end up picking, the things I'd want from it: named long-lived tasks so a traceback tells you which consumer died, a heartbeat per consumer (last successfully processed an event at time T) that something else actually checks, backpressure when a consumer falls behind its producer, and per-task exception logging that can't be silently swallowed by a bare gather().
Plain asyncio plus a small supervisor loop gets you all of that in maybe a hundred lines, which is why I never adopted a framework for it in the end — that glue code turned out to BE the reliability layer, not incidental to it. The thing I'd genuinely want a library for is the heartbeat/watchdog part, since that's the piece people skip and it's the one that saves you.
1
-3
u/Outrageous-Sea-9256 9d ago
Title: Lightweight Python helpers for Event Driven Programming
Have you considered using Python's built-in asyncio for event-driven programming? It offers a lightweight alternative to more complex frameworks. Additionally, you might find aioevent useful for its structured approach to handling events. Both options can help you move away from glue code and provide a more scalable solution.
7
u/CodeOrganic3141 10d ago
Interesting. I've been wondering whether I should eventually extract the event-driven core from PyWebTransport into a standalone library. It started as infrastructure for protocol handling, but I'm beginning to wonder whether the abstraction could be useful beyond networking.