This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

observed allows you to to sign up functions or methods to “observe” other functions or methods:

from observed import event

@event
def observed_func(arg):
    print("observed_func: %s"%(arg,))

def observer_func(arg):
    print("observer_func: %s"%(arg,))

observed_func.add_observer(observer_func)
observed_func('banana')

>>> observed_func: banana
>>> observer_func: banana

You can also register observers for bound methods:

from observed import event

class Foo(object):
    def __init__(self, name):
        self.name = name

    @event
    def bar(self, arg):
        print("Object %s invoked bar with arg='%s'"%(self.name,arg))

def callback(arg):
    print("callback was invoked with arg='%s'"%(arg,))

a = Foo('a')
b = Foo('b')
# Sign up b.bar and callback to "observe" a.bar
a.bar.add_observer(b.bar)
a.bar.add_observer(callback)
# Now when we call a.bar, b.bar and callback will be invoked with
# the same arguments
a.bar('baz')

>>> Object a invoked bar with arg='baz'
>>> Object b invoked bar with arg='baz'
>>> callback was invoked with arg='baz'

This example is included in ./observed/example.py.

You can ask that the observed object pass itself as the first argument whenever it calls observers:

from observed import event

@event
def observed_func():
    print("observed_func: I was called")

def observer_func(observed):
    print("observer_func: %s called me"%(observed.__name__,))

observed_func.add_observer(observer_func, identify_observed=True)
observed_func()

>>> observed_func: I was called
>>> observer_func: observed_func called me

Notable features include:

  • A function or bound method is not kept alive just because it is observing something else. This is because the observed object does not keep any strong references to the observing objects.
  • The @event decorator can be used on methods in classes which are unhashable types, and can be used on an arbitrary number of methods in each class.
  • Tests included :)

Installation

observed exists on the python package index, so you can do pip install observed to install it. Alternatively, you can download the source distribution and in the root directory of the distribution do

$ python setup.py install.

News

See the file NEWS for the user-visible changes from previous releases.

License

observed is free (as in beer) software. See the LICENSE file.

Downloading

observed can be obtained from the python package index

https://pypi.python.org/pypi/observed

or via git

https://github.com/DanielSank/observed.git

Documentation

Basic usage is illustrated at the top of this file. Further examples are given in ./observed/example.py

The source code is documented. Docstrings are required in contributions.

Development

observed development is hosted on github. The current working repository is given in the Downloading section above.

Bug Reporting

Please submit bug tickets on the github tracking system

https://github.com/DanielSank/observed/issues

Release History

Release History

0.4

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
observed-0.4.zip (8.1 kB) Copy SHA256 Checksum SHA256 Source May 29, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting