{ "info": { "author": "Daniel Sank", "author_email": "sank.daniel@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "**observed** allows you to to sign up functions or methods to \"observe\"\nother functions or methods:\n\n```python\nfrom observed import observable_function\n\n@observable_function\ndef observed_func(arg):\n print(\"observed_func: %s\"%(arg,))\n\ndef observer_func(arg):\n print(\"observer_func: %s\"%(arg,))\n\nobserved_func.add_observer(observer_func)\nobserved_func('banana')\n\n>>> observed_func: banana\n>>> observer_func: banana\n```\n\nYou can also register observers for bound methods:\n\n```python\nfrom observed import observable_method\n\nclass Foo:\n def __init__(self, name):\n self.name = name\n\n @observable_method()\n def bar(self, arg):\n print(\"Object %s invoked bar with arg='%s'\"%(self.name, arg))\n\n def baz(self, arg):\n print(\"Object %s invoked baz with arg='%s'\"%(self.name, arg))\n\ndef callback(arg):\n print(\"callback was invoked with arg='%s'\"%(arg,))\n\na = Foo('a')\nb = Foo('b')\na.bar.add_observer(b.bar)\na.bar.add_observer(b.baz)\na.bar.add_observer(callback)\na.bar('banana')\n\n>>> Object a invoked bar with arg='banana'\n>>> Object b invoked bar with arg='banana'\n>>> Object b invoked baz with arg='banana'\n>>> callback was invoked with arg='banana'\n```\n\nYou can ask that the observed object pass itself as the first argument\nwhenever it calls observers:\n\n```python\nfrom observed import observable_function\n\n@observable_function\ndef observed_func():\n print(\"observed_func: I was called\")\n\ndef observer_func(observed):\n print(\"observer_func: %s called me\"%(observed.__name__,))\n\nobserved_func.add_observer(observer_func, identify_observed=True)\nobserved_func()\n\n>>> observed_func: I was called\n>>> observer_func: observed_func called me\n```\n\nWhen observed bound methods pass themselves as the observed object, keep in\nmind that you can always access the associated instance via `__self__`:\n\n```python\nfrom observed import observable_method\n\nclass Foo:\n def __init__(self, name):\n self.name = name\n\n @observable_method()\n def bar(self):\n print(\"Object %s invoked bar\"%(self.name,))\n\ndef callback(observed):\n print(\"callback was invoked by='%s'\"%(observed.__self__.name,))\n\na = Foo('a')\na.bar.add_observer(callback, identify_observed=True)\na.bar()\n\n>>> Object a invoked bar\n>>> callback was invoked by a\n```\n\nNotable features include:\n\n* A function or bound method is not kept alive just because it is\n observing something else. This is because the observed object does\n not keep any strong references to the observing objects. In CPython\n this means that your observers are automatically detached whenever the\n reference count to that observer goes to zero.\n\n* The observable_method decorator can be used on methods in classes\n which are unhashable types, and can be used on an arbitrary number of\n methods in each class...\n\n* ...but the descriptor which handles observable_method does not paste\n any data onto the instances it manages. There is zero chance of name\n collision on the observed instances.\n\n\n## Installation\n\n**observed** exists on the python package index, so you can do\n`pip install observed` to install it. Alternatively, you can\ndownload the source distribution and in the root directory of the\ndistribution do\n\n```\n$ python setup.py install\n```\n\n\n## News\n\nSee the file NEWS for the user-visible changes from previous releases.\n\n\n## License\n\nSee `LICENSE.txt`.\n\n\n## Downloading\n\nobserved can be obtained from the\n[python package index at](https://pypi.python.org/pypi/observed)\nor via [GitHub](https://github.com/DanielSank/observed.git).\n\n\n## Documentation\n\nBasic usage is illustrated at the top of this file. Further examples are\ngiven in `example.py`.\n\n\n## Development\n\nobserved development is hosted on github. The current working repository\nis given in the Downloading section above.\n\n\n## Bug Reporting\n\nPlease submit bug tickets on the\n[GitHub tracking system](https://github.com/DanielSank/observed/issues).\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/DanielSank/observed", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "observed", "package_url": "https://pypi.org/project/observed/", "platform": "", "project_url": "https://pypi.org/project/observed/", "project_urls": { "Homepage": "https://github.com/DanielSank/observed" }, "release_url": "https://pypi.org/project/observed/0.5.3/", "requires_dist": null, "requires_python": "", "summary": "Observer pattern for functions and bound methods", "version": "0.5.3" }, "last_serial": 5330524, "releases": { "0.2.2": [ { "comment_text": "", "digests": { "md5": "ff3824ee50b2aa678a8e7740eb958bfb", "sha256": "b8fc55a5b6d35f48261728688dd51faf53249bc32a6a9145fb50c0de1f0780ae" }, "downloads": -1, "filename": "observed-0.2.2.zip", "has_sig": false, "md5_digest": "ff3824ee50b2aa678a8e7740eb958bfb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6473, "upload_time": "2014-05-25T06:42:10", "url": "https://files.pythonhosted.org/packages/19/17/51a639be7478b2cbfec4958b14ef1e043064d575fe2a80490aaed0f06132/observed-0.2.2.zip" } ], "0.2.4": [ { "comment_text": "", "digests": { "md5": "0dd57b505604c82dbc451003263513ea", "sha256": "f3c819a9e00b151156e2b3363b58e2a6b9a2a04dc5cf926707587a504466b4ba" }, "downloads": -1, "filename": "observed-0.2.4.zip", "has_sig": false, "md5_digest": "0dd57b505604c82dbc451003263513ea", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7828, "upload_time": "2014-05-26T02:28:44", "url": "https://files.pythonhosted.org/packages/e4/08/2afd9ac17bd0b6d64d150d8171bccc48a9498d1d8507a8b9d8acffd43efe/observed-0.2.4.zip" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "e05f2fcc85f513c0708436676f6dee19", "sha256": "b2bec7af5454a117ca0b9daed01a4ff47fa24d1afd737ed3c9080f2150333422" }, "downloads": -1, "filename": "observed-0.3.zip", "has_sig": false, "md5_digest": "e05f2fcc85f513c0708436676f6dee19", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8089, "upload_time": "2014-05-26T04:41:50", "url": "https://files.pythonhosted.org/packages/95/af/075f17f73e7cedc612fd3baf2ac81261ed146b2b775fe974f935d72b189c/observed-0.3.zip" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "dff1001306a810ab87c294a98780ee9e", "sha256": "bee8923936886bf6a43140cfa69d51cf1832b1afd3ec14eb56bb60c4b26b168c" }, "downloads": -1, "filename": "observed-0.4.zip", "has_sig": false, "md5_digest": "dff1001306a810ab87c294a98780ee9e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8124, "upload_time": "2014-05-29T15:33:05", "url": "https://files.pythonhosted.org/packages/04/79/6991825db7d7fe97e2875dda594b0f76e7a2eb0463bdd6bdcce3e3eb2e22/observed-0.4.zip" } ], "0.5.1": [ { "comment_text": "", "digests": { "md5": "23a0b7a6de1e54f6a9452f8a078289a6", "sha256": "36d19fe3a22ece8b474e5a3753728ae51c00b122d57ff9f1782bd7f3ae640733" }, "downloads": -1, "filename": "observed-0.5.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "23a0b7a6de1e54f6a9452f8a078289a6", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 3317, "upload_time": "2019-05-26T18:07:12", "url": "https://files.pythonhosted.org/packages/e7/dc/a2b9436e76cc639a01cc77ffa3c4a450d1dd03df73b8354cdfd79d34b032/observed-0.5.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a1bf017ae0cc4e0edbd3e447bed98209", "sha256": "d16d0808215a1eb051d04d4ee42d91c3890141a9c7d3af692be018a4e534214a" }, "downloads": -1, "filename": "observed-0.5.1.tar.gz", "has_sig": false, "md5_digest": "a1bf017ae0cc4e0edbd3e447bed98209", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2979, "upload_time": "2019-05-26T18:07:13", "url": "https://files.pythonhosted.org/packages/ea/4b/1d01f310c1fb566372de57e9e529ccc5f3e64a2cb14c24edfb42cf5d31c2/observed-0.5.1.tar.gz" } ], "0.5.3": [ { "comment_text": "", "digests": { "md5": "5602d54898209bded84fd4dc6ba713c1", "sha256": "aabf021739cb0c79aca2cfd97caed6a1e0146883ec56dcf15bfa9cdb83860a88" }, "downloads": -1, "filename": "observed-0.5.3-py3-none-any.whl", "has_sig": false, "md5_digest": "5602d54898209bded84fd4dc6ba713c1", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9521, "upload_time": "2019-05-29T05:11:07", "url": "https://files.pythonhosted.org/packages/87/af/ff0eb909e299225d4c750551893270863ba1b61f7280c8d7b6a8e4d61b36/observed-0.5.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e4952548475155011da1435402e8f275", "sha256": "b7e925ef174f6b8587b6d0890958de95da0203c874f968397dbd1ce24002fef6" }, "downloads": -1, "filename": "observed-0.5.3.tar.gz", "has_sig": false, "md5_digest": "e4952548475155011da1435402e8f275", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8761, "upload_time": "2019-05-29T05:11:09", "url": "https://files.pythonhosted.org/packages/a1/21/94244e118a162a320b19cc4d96d5398ebdf8482aa39a61a8a10a13403307/observed-0.5.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5602d54898209bded84fd4dc6ba713c1", "sha256": "aabf021739cb0c79aca2cfd97caed6a1e0146883ec56dcf15bfa9cdb83860a88" }, "downloads": -1, "filename": "observed-0.5.3-py3-none-any.whl", "has_sig": false, "md5_digest": "5602d54898209bded84fd4dc6ba713c1", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9521, "upload_time": "2019-05-29T05:11:07", "url": "https://files.pythonhosted.org/packages/87/af/ff0eb909e299225d4c750551893270863ba1b61f7280c8d7b6a8e4d61b36/observed-0.5.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e4952548475155011da1435402e8f275", "sha256": "b7e925ef174f6b8587b6d0890958de95da0203c874f968397dbd1ce24002fef6" }, "downloads": -1, "filename": "observed-0.5.3.tar.gz", "has_sig": false, "md5_digest": "e4952548475155011da1435402e8f275", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8761, "upload_time": "2019-05-29T05:11:09", "url": "https://files.pythonhosted.org/packages/a1/21/94244e118a162a320b19cc4d96d5398ebdf8482aa39a61a8a10a13403307/observed-0.5.3.tar.gz" } ] }