skip to navigation
skip to content

signalslot 0.0.2

Simple Signal/Slot implementation

Latest Version: 0.1.0

signalslot: simple Signal/Slot implementation for Python

This package provides a simple and stupid implementation of the Signal/Slot pattern for Python. Wikipedia has a nice introduction:

Signals and slots is a language construct introduced in Qt for communication between objects[1] which makes it easy to implement the Observer pattern while avoiding boilerplate code.

Why signalslot ?

Signal/Slot is a pattern that allows loose coupling various components of a software without having to introduce boilerplate code. Loose coupling of components allows better modularity in software code which has the nice side effect of making it easier to test because less dependencies means less mocking and monkey patching.

Signal/Slot is a widely used pattern, many frameworks have it built-in including Django, Qt and probably many others. If you have a standalone project then you probably don’t want to add a big dependency like PyQt or Django just for a Signal/Slot framework. There are a couple of standalone libraries which allow to acheive a similar result, like Circuits or PyPubSub, which has way more features than signalslots, like messaging over the network and is a quite complicated and has weird (non-PyPi hosted) dependencies and is not PEP8 compliant …

signalslot has the vocation of being a light and simple implementation of the well known Signal/Slot design pattern provided as a classic quality Python package.


Install latest stable version:

pip install signalslot

Install development version:

pip install -e git+


Tight coupling

Consider such a code in

import your_service
import your_plugin

class YourClient(object):
    def something_happens(self, some_argument):

The problem with that code is that it ties your_client with your_service and your_plugin, which makes it harder to test and maintain.

An improvement would be to acheive the same while keeping components loosely coupled.

Observer pattern

You could implement an Observer pattern in YourClient by adding boilerplate code:

class YourClient(object):
    def __init__(self):
        self.observers = []

    def register_observer(self, observer):

    def something_happens(self, some_argument):
        for observer in self.observers:

This implementation is a bit dumb, it doesn’t check the compatibility of observers for example, also it’s additionnal code you’d have to test.

And, this would work if you have control on instanciation of YourClient, ie.:

your_client = YourClient()

If YourClient is used by a framework with IoC (Inversion of Control) then it’s a lot harder. Example:

client = some_framework.Service.create(

As you can see in the above example, it’s a lot harder to get your hands on the YourClient instance and call register_observer.

Using signalslot

Consider such a signal definition in your_client/

import signalslot

something_happens = signalslot.Signal(args=['some_argument'])

You can then connect slots to this signal in each loosely coupled module. your_service/ and your_plugin/ would contain something like:

from your_client.signals import something_happens

def something_happens(some_argument):
    # ....


Then, your_service.something_happens and your_plugin.something_happens would be called every time the something_happens signal is emited, ie.:

from . import signals

class YourClient(object):
    def something_happens(self, some_argument):

All you have to do is import your_client and your_plugin somewhere before YourClient to ensure that the connect() calls are executed, ie.:

from your_service import slots
from your_plugin import slots

client = some_framework.Service.create(
File Type Py Version Uploaded on Size
signalslot-0.0.2.tar.gz (md5) Source 2014-03-19 4KB
  • Downloads (All Versions):
  • 15 downloads in the last day
  • 158 downloads in the last week
  • 889 downloads in the last month