Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

A very simple implementation of the observer pattern

Project description

PyPI Build Status Coverage Status

A simple implementation of the observer pattern.

import simpleobserver
# Create a subject and list the events it might fire
foo = simpleobserver.Subject('bar', 'baz')

# Add a listener
def foo_bar_listener(*args):
   print("heard 'bar'", args)

foo('bar', foo_bar_listener)

# fire events
foo.fire('bar', 1, 2, 3)
# -> heard 'bar' (1, 2, 3)

# Trying to listen to an unregistered event throws an error
foo('snorble', lambda: None)
# -> AssertionError: snorble is not a valid event for this subject

# Same with trying to fire an unregistered event
foo.fire('snorble')
# -> AssertionError: snorble is not a valid event for this subject

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for simpleobserver, version 1.0.3
Filename, size File type Python version Upload date Hashes
Filename, size simpleobserver-1.0.3.tar.gz (2.0 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page