Python Event Bus Patterns — ELI5

Imagine your school has an intercom system. When the principal has an announcement — “Pizza day in the cafeteria!” — they speak into the microphone. Every classroom hears it at the same time. The principal does not need to walk to each room. The classrooms do not need to check for announcements. The intercom handles everything.

An event bus in a Python program works like that intercom. One part of the program says “something happened!” (like “a new order was placed”), and any other part that cares about that news hears it automatically.

The beautiful thing is that the announcer does not need to know who is listening. The principal does not care which classrooms have their speakers on. Similarly, the code that creates an order does not need to know that the email system, the inventory tracker, and the analytics logger all want to hear about it.

This makes programs easier to change. Want to add a new listener? Just plug it in. Want to remove one? Unplug it. The announcer stays the same either way.

In Python, an event bus can be as simple as a list of functions. When an event fires, you loop through the list and call each function. Libraries like pyee or blinker make this even easier by handling the subscription and notification plumbing for you.

The one thing to remember: An event bus is a notification system inside your Python program where parts can announce events and other parts can listen — without anyone needing to know about each other.

pythonevent-busarchitecturepatterns

See Also