pythonpublish-subscribepypubsub

Recommended Python publish/subscribe/dispatch module?


From PyPubSub:

Pypubsub provides a simple way for your Python application to decouple its components: parts of your application can publish messages (with or without data) and other parts can subscribe/receive them. This allows message "senders" and message "listeners" to be unaware of each other:

  • one doesn't need to import the other
  • a sender doesn't need to know
    • "who" gets the messages,
    • what the listeners will do with the data,
    • or even if any listener will get the message data.
  • similarly, listeners don't need to worry about where messages come from.

This is a great tool for implementing a Model-View-Controller architecture or any similar architecture that promotes decoupling of its components.

There seem to be quite a few Python modules for publishing/subscribing floating around the web, from PyPubSub, to PyDispatcher to simple "home-cooked" classes.

Are there specific advantages and disadvantages when comparing different different modules? Which sets of modules have been benchmarked and compared?

Thanks in advance


Solution

  • PyDispatcher is used heavily in Django and it's working perfectly for me (and for whole Django community, I guess).

    As I remember, there are some performance issues:

    AFAIK it's very unlikely you will run into this issues in a small-to-medium sized application. So these issues may not concern you. If you think you need every pound of performance (premature optimization is the root of all evil!), you can look at modifications done to PyDispatcher in Django.

    Hope this helps.