Package: obsub
Small python module that implements the observer pattern via a
decorator.Deprecation noticeThis module has been unmaintained since around 2014. The authors have
moved on to other alternatives to event handling. There is alsoobservedby @DanielSank, which
was partially inspired byobsub, however, has not seen many updates lately.
@milibopp has been writing with functional reactive programming (FRP), but
not for Python.FRP is a higher-level abstraction than the observer pattern, that essentially
is a purely functional approach to unidirectional dataflow, composing your
programs of event stream transformations. Experience has shown, that is easier
to compose and to test than the raw observer pattern. A solid implementation in
Python isRxPY, part of the ReactiveX
project.DescriptionThis is based on athread on stackoverflow(the example of C#-like events by Jason Orendorff), so I don’t take any
credit for the idea. I merely made a fancy module with documentation and
tests out of it, since I needed it in a bigger project. It is quite
handy and I’ve been using it in a couple of projects, which require some
sort of event handling.Thus it islicensed as
CC0, so basically
do-whatever-you-want to the extent legally possible.Installationobsubis available on PyPI, so you can simply install it usingpip install obsubor you do it manually usingsetup.pyas with
any python package.UsageTheeventdecorator from theobsubmodule is used as follows:fromobsubimportevent# Define a class with an eventclassSubject(object):@eventdefon_stuff(self,arg):print('Stuff{}happens'.format(arg))# Now define an event handler, the observerdefhandler(subject,arg):print('Stuff{}is handled'.format(arg))# Wire everything up...sub=Subject()sub.on_stuff+=handler# And try it!sub.on_stuff('foo')You should now get both print messages from the event itself and the
event handler function, like so:Stuff foo happens
Stuff foo is handledContribution and feedbackobsubis developed ongithub.If you have any questions about this software or encounter bugs, you’re welcome
to open anew issue on github.In case you do not want to use github for some reason, you can alternatively
send an email one of us:Emilia BoppAndré-Patrick BubelThomas GläßleFeel free to contribute patches as pull requests as you see fit. Try to be
consistent with PEP 8 guidelines as far as possible and test everything.
Otherwise, your commit messages should start with a capitalized verb for
consistency. Unless your modification is completely trivial, also add a message
body to your commit.CreditsThanks to Jason Orendorff on for the idea on stackoverflow. I also want
to thank @coldfix and @Moredread for contributions and feedback.Changelogv0.2From a user perspective the preservation of function signatures and a couple of
bug fixes are probably most relevant. Python 2.5 is no longer tested by
continuous integration, though we try to avoid unnecessary changes that might
break backwards compatibility.In addition, there are quite a number of changes that mostly concern
developers.Function signatures are now preserved correctly by the event decorator. This
is true only for python3. On python2 there is no support for default
arguments, currentlySome fixes to memory handling and tests thereof. This includes a more generic
handling of the garbage collection process within the test suite to make it
pass on pypy, too.Massive refactoring of test suite from one very long doctest to more focused
unit tests.The documentation has been converted from Markdown to reStructuredText, since
it is compatible with both PyPI and GitHub.Various improvements and some streamlining of the documentation.Fix package name in license.Continuous integration now includes coveralls.io support.Support for Python 2.5 is no longer tested using Travis CI, since they have
dropped support for this version.v0.1.1Add __all__ attribute to moduleFix a couple of documentation issuesv0.1Initial release