python-dispatch


Namepython-dispatch JSON
Version 0.2.2 PyPI version JSON
download
home_pagehttps://github.com/nocarryr/python-dispatch
SummaryLightweight Event Handling
upload_time2023-06-22 16:53:22
maintainer
docs_urlhttps://pythonhosted.org/python-dispatch/
authorMatthew Reid
requires_python
licenseMIT
keywords event properties dispatch
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # python-dispatch
Lightweight event handling for Python

[![Build Status](https://travis-ci.org/nocarryr/python-dispatch.svg?branch=master)](https://travis-ci.org/nocarryr/python-dispatch)[![Coverage Status](https://coveralls.io/repos/github/nocarryr/python-dispatch/badge.svg?branch=master)](https://coveralls.io/github/nocarryr/python-dispatch?branch=master)[![PyPI version](https://badge.fury.io/py/python-dispatch.svg)](https://badge.fury.io/py/python-dispatch)[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/nocarryr/python-dispatch/master/LICENSE.txt)

## Description
This is an implementation of the "Observer Pattern" with inspiration from the
[Kivy](kivy.org) framework. Many of the features though are intentionally
stripped down and more generalized. The goal is to have a simple drop-in
library with no dependencies that stays out of the programmer's way.

## Installation
"python-dispatch" is available on [PyPI](https://pypi.org/project/python-dispatch/)
and can be installed using pip:

```bash
pip install python-dispatch
```

### Python Requirements
After version `0.1` of this project, only Python 3.6 and above will be supported.
If using an older Python version, the older releases should still be available
on PyPI and the correct package should be chosen automatically by `pip`.
If not, either upgrade `pip` and `setuptools`:

```bash
pip install -U pip setuptools
```

Or specify the version manually:

```bash
pip install python-dispatch<0.2
```

## Links

|               |                                              |
| -------------:|:-------------------------------------------- |
| Project Home  | https://github.com/nocarryr/python-dispatch  |
| PyPI          | https://pypi.python.org/pypi/python-dispatch |
| Documentation | https://python-dispatch.readthedocs.io       |


## Usage

### Events

```python
>>> from pydispatch import Dispatcher

>>> class MyEmitter(Dispatcher):
...     # Events are defined in classes and subclasses with the '_events_' attribute
...     _events_ = ['on_state', 'new_data']
...     def do_some_stuff(self):
...         # do stuff that makes new data
...         data = {'foo':'bar'}
...         # Then emit the change with optional positional and keyword arguments
...         self.emit('new_data', data=data)

>>> # An observer - could inherit from Dispatcher or any other class
>>> class MyListener(object):
...     def on_new_data(self, *args, **kwargs):
...         data = kwargs.get('data')
...         print('I got data: {}'.format(data))
...     def on_emitter_state(self, *args, **kwargs):
...         print('emitter state changed')

>>> emitter = MyEmitter()
>>> listener = MyListener()

>>> # Bind to the "on_state" and "new_data" events of emitter
>>> emitter.bind(on_state=listener.on_emitter_state)
>>> emitter.bind(new_data=listener.on_new_data)

>>> emitter.do_some_stuff()
I got data: {'foo': 'bar'}
>>> emitter.emit('on_state')
emitter state changed

```

### Properties

```python
>>> from pydispatch import Dispatcher, Property

>>> class MyEmitter(Dispatcher):
...     # Property objects are defined and named at the class level.
...     # They will become instance attributes that will emit events when their values change
...     name = Property()
...     value = Property()

>>> class MyListener(object):
...     def on_name(self, instance, value, **kwargs):
...         print('emitter name is {}'.format(value))
...     def on_value(self, instance, value, **kwargs):
...         print('emitter value is {}'.format(value))

>>> emitter = MyEmitter()
>>> listener = MyListener()

>>> # Bind to the "name" and "value" properties of emitter
>>> emitter.bind(name=listener.on_name, value=listener.on_value)

>>> # Set emitter.name property (triggering the on_name callback)
>>> emitter.name = 'foo'
emitter name is foo

>>> # Set emitter.value (triggering the on_value callback)
>>> emitter.value = 42
emitter value is 42

```

## Contributing

Contributions are welcome!

If you want to contribute through code or documentation, please see the
[Contributing Guide](CONTRIBUTING.md) for information.

## License

This project is released under the MIT License. See the [LICENSE](LICENSE.txt) file
for more information.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/nocarryr/python-dispatch",
    "name": "python-dispatch",
    "maintainer": "",
    "docs_url": "https://pythonhosted.org/python-dispatch/",
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "event properties dispatch",
    "author": "Matthew Reid",
    "author_email": "matt@nomadic-recording.com",
    "download_url": "https://files.pythonhosted.org/packages/03/44/3cf80a3931741fb97dbfaff1b2a8bf0174b18610d2bbc89ee12b19c3220b/python-dispatch-0.2.2.tar.gz",
    "platform": "any",
    "description": "# python-dispatch\nLightweight event handling for Python\n\n[![Build Status](https://travis-ci.org/nocarryr/python-dispatch.svg?branch=master)](https://travis-ci.org/nocarryr/python-dispatch)[![Coverage Status](https://coveralls.io/repos/github/nocarryr/python-dispatch/badge.svg?branch=master)](https://coveralls.io/github/nocarryr/python-dispatch?branch=master)[![PyPI version](https://badge.fury.io/py/python-dispatch.svg)](https://badge.fury.io/py/python-dispatch)[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/nocarryr/python-dispatch/master/LICENSE.txt)\n\n## Description\nThis is an implementation of the \"Observer Pattern\" with inspiration from the\n[Kivy](kivy.org) framework. Many of the features though are intentionally\nstripped down and more generalized. The goal is to have a simple drop-in\nlibrary with no dependencies that stays out of the programmer's way.\n\n## Installation\n\"python-dispatch\" is available on [PyPI](https://pypi.org/project/python-dispatch/)\nand can be installed using pip:\n\n```bash\npip install python-dispatch\n```\n\n### Python Requirements\nAfter version `0.1` of this project, only Python 3.6 and above will be supported.\nIf using an older Python version, the older releases should still be available\non PyPI and the correct package should be chosen automatically by `pip`.\nIf not, either upgrade `pip` and `setuptools`:\n\n```bash\npip install -U pip setuptools\n```\n\nOr specify the version manually:\n\n```bash\npip install python-dispatch<0.2\n```\n\n## Links\n\n|               |                                              |\n| -------------:|:-------------------------------------------- |\n| Project Home  | https://github.com/nocarryr/python-dispatch  |\n| PyPI          | https://pypi.python.org/pypi/python-dispatch |\n| Documentation | https://python-dispatch.readthedocs.io       |\n\n\n## Usage\n\n### Events\n\n```python\n>>> from pydispatch import Dispatcher\n\n>>> class MyEmitter(Dispatcher):\n...     # Events are defined in classes and subclasses with the '_events_' attribute\n...     _events_ = ['on_state', 'new_data']\n...     def do_some_stuff(self):\n...         # do stuff that makes new data\n...         data = {'foo':'bar'}\n...         # Then emit the change with optional positional and keyword arguments\n...         self.emit('new_data', data=data)\n\n>>> # An observer - could inherit from Dispatcher or any other class\n>>> class MyListener(object):\n...     def on_new_data(self, *args, **kwargs):\n...         data = kwargs.get('data')\n...         print('I got data: {}'.format(data))\n...     def on_emitter_state(self, *args, **kwargs):\n...         print('emitter state changed')\n\n>>> emitter = MyEmitter()\n>>> listener = MyListener()\n\n>>> # Bind to the \"on_state\" and \"new_data\" events of emitter\n>>> emitter.bind(on_state=listener.on_emitter_state)\n>>> emitter.bind(new_data=listener.on_new_data)\n\n>>> emitter.do_some_stuff()\nI got data: {'foo': 'bar'}\n>>> emitter.emit('on_state')\nemitter state changed\n\n```\n\n### Properties\n\n```python\n>>> from pydispatch import Dispatcher, Property\n\n>>> class MyEmitter(Dispatcher):\n...     # Property objects are defined and named at the class level.\n...     # They will become instance attributes that will emit events when their values change\n...     name = Property()\n...     value = Property()\n\n>>> class MyListener(object):\n...     def on_name(self, instance, value, **kwargs):\n...         print('emitter name is {}'.format(value))\n...     def on_value(self, instance, value, **kwargs):\n...         print('emitter value is {}'.format(value))\n\n>>> emitter = MyEmitter()\n>>> listener = MyListener()\n\n>>> # Bind to the \"name\" and \"value\" properties of emitter\n>>> emitter.bind(name=listener.on_name, value=listener.on_value)\n\n>>> # Set emitter.name property (triggering the on_name callback)\n>>> emitter.name = 'foo'\nemitter name is foo\n\n>>> # Set emitter.value (triggering the on_value callback)\n>>> emitter.value = 42\nemitter value is 42\n\n```\n\n## Contributing\n\nContributions are welcome!\n\nIf you want to contribute through code or documentation, please see the\n[Contributing Guide](CONTRIBUTING.md) for information.\n\n## License\n\nThis project is released under the MIT License. See the [LICENSE](LICENSE.txt) file\nfor more information.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Lightweight Event Handling",
    "version": "0.2.2",
    "project_urls": {
        "Documentation": "https://python-dispatch.readthedocs.io",
        "Homepage": "https://github.com/nocarryr/python-dispatch",
        "Source": "https://github.com/nocarryr/python-dispatch",
        "Tracker": "https://github.com/nocarryr/python-dispatch/issues"
    },
    "split_keywords": [
        "event",
        "properties",
        "dispatch"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ccd58776e1bdd008c093e68f0a78dbc0c0d52f602c539eb218fe3e10661c9195",
                "md5": "c1efa95b7f4a607e31fa9a897fac6feb",
                "sha256": "0305898bf011fb164bb21e0f48809cf21faee6d8ea311177bd9a43f86201b9cd"
            },
            "downloads": -1,
            "filename": "python_dispatch-0.2.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c1efa95b7f4a607e31fa9a897fac6feb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 17205,
            "upload_time": "2023-06-22T16:53:20",
            "upload_time_iso_8601": "2023-06-22T16:53:20.868234Z",
            "url": "https://files.pythonhosted.org/packages/cc/d5/8776e1bdd008c093e68f0a78dbc0c0d52f602c539eb218fe3e10661c9195/python_dispatch-0.2.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "03443cf80a3931741fb97dbfaff1b2a8bf0174b18610d2bbc89ee12b19c3220b",
                "md5": "1192b4e4ab1f746ff01e96599303dcb3",
                "sha256": "d05278ff76625a53865c92ca6b5069e82c27b5741999f7ec737c64180f0123e6"
            },
            "downloads": -1,
            "filename": "python-dispatch-0.2.2.tar.gz",
            "has_sig": false,
            "md5_digest": "1192b4e4ab1f746ff01e96599303dcb3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 24969,
            "upload_time": "2023-06-22T16:53:22",
            "upload_time_iso_8601": "2023-06-22T16:53:22.411084Z",
            "url": "https://files.pythonhosted.org/packages/03/44/3cf80a3931741fb97dbfaff1b2a8bf0174b18610d2bbc89ee12b19c3220b/python-dispatch-0.2.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-22 16:53:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "nocarryr",
    "github_project": "python-dispatch",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "python-dispatch"
}
        
Elapsed time: 0.17886s