eventkit


Nameeventkit JSON
Version 1.0.3 PyPI version JSON
download
home_pagehttps://github.com/erdewit/eventkit
SummaryEvent-driven data pipelines
upload_time2023-12-11 11:41:35
maintainer
docs_urlNone
authorEwald R. de Wit
requires_python
licenseBSD
keywords python asyncio event driven data pipelines
VCS
bugtrack_url
requirements numpy
Travis-CI No Travis.
coveralls test coverage No coveralls.
            |Build| |PyVersion| |Status| |PyPiVersion| |License| |Docs|

Introduction
------------

The primary use cases of eventkit are

* to send events between loosely coupled components;
* to compose all kinds of event-driven data pipelines.

The interface is kept as Pythonic as possible,
with familiar names from Python and its libraries where possible.
For scheduling asyncio is used and there is seamless integration with it.

See the examples and the
`introduction notebook <https://github.com/erdewit/eventkit/tree/master/notebooks/eventkit_introduction.ipynb>`_
to get a true feel for the possibilities.

Installation
------------

::

    pip3 install eventkit

Python_ version 3.6 or higher is required.


Examples
--------

**Create an event and connect two listeners**

.. code-block:: python

    import eventkit as ev

    def f(a, b):
        print(a * b)

    def g(a, b):
        print(a / b)

    event = ev.Event()
    event += f
    event += g
    event.emit(10, 5)

**Create a simple pipeline**

.. code-block:: python

    import eventkit as ev

    event = (
        ev.Sequence('abcde')
        .map(str.upper)
        .enumerate()
    )

    print(event.run())  # in Jupyter: await event.list()

Output::

    [(0, 'A'), (1, 'B'), (2, 'C'), (3, 'D'), (4, 'E')]

**Create a pipeline to get a running average and standard deviation**

.. code-block:: python

    import random
    import eventkit as ev

    source = ev.Range(1000).map(lambda i: random.gauss(0, 1))

    event = source.array(500)[ev.ArrayMean, ev.ArrayStd].zip()

    print(event.last().run())  # in Jupyter: await event.last()

Output::

    [(0.00790957852672618, 1.0345673260655333)]

**Combine async iterators together**

.. code-block:: python

    import asyncio
    import eventkit as ev

    async def ait(r):
        for i in r:
            await asyncio.sleep(0.1)
            yield i

    async def main():
        async for t in ev.Zip(ait('XYZ'), ait('123')):
            print(t)

    asyncio.get_event_loop().run_until_complete(main())  # in Jupyter: await main()

Output::

    ('X', '1')
    ('Y', '2')
    ('Z', '3')

**Real-time video analysis pipeline**

.. code-block:: python

    self.video = VideoStream(conf.CAM_ID)
    scene = self.video | FaceTracker | SceneAnalyzer
    lastScene = scene.aiter(skip_to_last=True)
    async for frame, persons in lastScene:
        ...

`Full source code <https://github.com/erdewit/heartwave/blob/100e1a89d18756e141f9dcfbb73c55a1009debf4/heartwave/app.py#L88>`_

Distributed computing
---------------------

The `distex <https://github.com/erdewit/distex>`_ library provides a
``poolmap`` extension method to put multiple cores or machines to use:

.. code-block:: python

    from distex import Pool
    import eventkit as ev
    import bz2

    pool = Pool()
    # await pool  # un-comment in Jupyter
    data = [b'A' * 1000000] * 1000

    pipe = ev.Sequence(data).poolmap(pool, bz2.compress).map(len).mean().last()

    print(pipe.run())  # in Jupyter: print(await pipe)
    pool.shutdown()


Inspired by:
------------

    * `Qt Signals & Slots <https://doc.qt.io/qt-5/signalsandslots.html>`_
    * `itertools <https://docs.python.org/3/library/itertools.html>`_
    * `aiostream <https://github.com/vxgmichel/aiostream>`_
    * `Bacon <https://baconjs.github.io/index.html>`_
    * `aioreactive <https://github.com/dbrattli/aioreactive>`_
    * `Reactive extensions <http://reactivex.io/documentation/operators.html>`_
    * `underscore.js <https://underscorejs.org>`_
    * `.NET Events <https://docs.microsoft.com/en-us/dotnet/standard/events>`_

Documentation
-------------

The complete `API documentation <https://eventkit.readthedocs.io/en/latest/api.html>`_.



.. _Python: http://www.python.org
.. _`Interactive Brokers Python API`: http://interactivebrokers.github.io

.. |Build| image:: https://github.com/erdewit/eventkit/actions/workflows/test.yml/badge.svg?branch=master
   :alt: Build
   :target: https://github.com/erdewit/eventkit/actions

.. |PyPiVersion| image:: https://img.shields.io/pypi/v/eventkit.svg
   :alt: PyPi
   :target: https://pypi.python.org/pypi/eventkit


.. |PyVersion| image:: https://img.shields.io/badge/python-3.6+-blue.svg
   :alt:

.. |Status| image:: https://img.shields.io/badge/status-stable-green.svg
   :alt:

.. |License| image:: https://img.shields.io/badge/license-BSD-blue.svg
   :alt:

.. |Docs| image:: https://readthedocs.org/projects/eventkit/badge/?version=latest
   :alt: Documentation
   :target: https://eventkit.readthedocs.io



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/erdewit/eventkit",
    "name": "eventkit",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "python asyncio event driven data pipelines",
    "author": "Ewald R. de Wit",
    "author_email": "ewald.de.wit@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/16/1e/0fac4e45d71ace143a2673ec642701c3cd16f833a0e77a57fa6a40472696/eventkit-1.0.3.tar.gz",
    "platform": null,
    "description": "|Build| |PyVersion| |Status| |PyPiVersion| |License| |Docs|\n\nIntroduction\n------------\n\nThe primary use cases of eventkit are\n\n* to send events between loosely coupled components;\n* to compose all kinds of event-driven data pipelines.\n\nThe interface is kept as Pythonic as possible,\nwith familiar names from Python and its libraries where possible.\nFor scheduling asyncio is used and there is seamless integration with it.\n\nSee the examples and the\n`introduction notebook <https://github.com/erdewit/eventkit/tree/master/notebooks/eventkit_introduction.ipynb>`_\nto get a true feel for the possibilities.\n\nInstallation\n------------\n\n::\n\n    pip3 install eventkit\n\nPython_ version 3.6 or higher is required.\n\n\nExamples\n--------\n\n**Create an event and connect two listeners**\n\n.. code-block:: python\n\n    import eventkit as ev\n\n    def f(a, b):\n        print(a * b)\n\n    def g(a, b):\n        print(a / b)\n\n    event = ev.Event()\n    event += f\n    event += g\n    event.emit(10, 5)\n\n**Create a simple pipeline**\n\n.. code-block:: python\n\n    import eventkit as ev\n\n    event = (\n        ev.Sequence('abcde')\n        .map(str.upper)\n        .enumerate()\n    )\n\n    print(event.run())  # in Jupyter: await event.list()\n\nOutput::\n\n    [(0, 'A'), (1, 'B'), (2, 'C'), (3, 'D'), (4, 'E')]\n\n**Create a pipeline to get a running average and standard deviation**\n\n.. code-block:: python\n\n    import random\n    import eventkit as ev\n\n    source = ev.Range(1000).map(lambda i: random.gauss(0, 1))\n\n    event = source.array(500)[ev.ArrayMean, ev.ArrayStd].zip()\n\n    print(event.last().run())  # in Jupyter: await event.last()\n\nOutput::\n\n    [(0.00790957852672618, 1.0345673260655333)]\n\n**Combine async iterators together**\n\n.. code-block:: python\n\n    import asyncio\n    import eventkit as ev\n\n    async def ait(r):\n        for i in r:\n            await asyncio.sleep(0.1)\n            yield i\n\n    async def main():\n        async for t in ev.Zip(ait('XYZ'), ait('123')):\n            print(t)\n\n    asyncio.get_event_loop().run_until_complete(main())  # in Jupyter: await main()\n\nOutput::\n\n    ('X', '1')\n    ('Y', '2')\n    ('Z', '3')\n\n**Real-time video analysis pipeline**\n\n.. code-block:: python\n\n    self.video = VideoStream(conf.CAM_ID)\n    scene = self.video | FaceTracker | SceneAnalyzer\n    lastScene = scene.aiter(skip_to_last=True)\n    async for frame, persons in lastScene:\n        ...\n\n`Full source code <https://github.com/erdewit/heartwave/blob/100e1a89d18756e141f9dcfbb73c55a1009debf4/heartwave/app.py#L88>`_\n\nDistributed computing\n---------------------\n\nThe `distex <https://github.com/erdewit/distex>`_ library provides a\n``poolmap`` extension method to put multiple cores or machines to use:\n\n.. code-block:: python\n\n    from distex import Pool\n    import eventkit as ev\n    import bz2\n\n    pool = Pool()\n    # await pool  # un-comment in Jupyter\n    data = [b'A' * 1000000] * 1000\n\n    pipe = ev.Sequence(data).poolmap(pool, bz2.compress).map(len).mean().last()\n\n    print(pipe.run())  # in Jupyter: print(await pipe)\n    pool.shutdown()\n\n\nInspired by:\n------------\n\n    * `Qt Signals & Slots <https://doc.qt.io/qt-5/signalsandslots.html>`_\n    * `itertools <https://docs.python.org/3/library/itertools.html>`_\n    * `aiostream <https://github.com/vxgmichel/aiostream>`_\n    * `Bacon <https://baconjs.github.io/index.html>`_\n    * `aioreactive <https://github.com/dbrattli/aioreactive>`_\n    * `Reactive extensions <http://reactivex.io/documentation/operators.html>`_\n    * `underscore.js <https://underscorejs.org>`_\n    * `.NET Events <https://docs.microsoft.com/en-us/dotnet/standard/events>`_\n\nDocumentation\n-------------\n\nThe complete `API documentation <https://eventkit.readthedocs.io/en/latest/api.html>`_.\n\n\n\n.. _Python: http://www.python.org\n.. _`Interactive Brokers Python API`: http://interactivebrokers.github.io\n\n.. |Build| image:: https://github.com/erdewit/eventkit/actions/workflows/test.yml/badge.svg?branch=master\n   :alt: Build\n   :target: https://github.com/erdewit/eventkit/actions\n\n.. |PyPiVersion| image:: https://img.shields.io/pypi/v/eventkit.svg\n   :alt: PyPi\n   :target: https://pypi.python.org/pypi/eventkit\n\n\n.. |PyVersion| image:: https://img.shields.io/badge/python-3.6+-blue.svg\n   :alt:\n\n.. |Status| image:: https://img.shields.io/badge/status-stable-green.svg\n   :alt:\n\n.. |License| image:: https://img.shields.io/badge/license-BSD-blue.svg\n   :alt:\n\n.. |Docs| image:: https://readthedocs.org/projects/eventkit/badge/?version=latest\n   :alt: Documentation\n   :target: https://eventkit.readthedocs.io\n\n\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "Event-driven data pipelines",
    "version": "1.0.3",
    "project_urls": {
        "Homepage": "https://github.com/erdewit/eventkit"
    },
    "split_keywords": [
        "python",
        "asyncio",
        "event",
        "driven",
        "data",
        "pipelines"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "93d97497d650b69b420e1a913329a843e16c715dac883750679240ef00a921e2",
                "md5": "4def44b13603d87f8df009011bc4230f",
                "sha256": "0e199527a89aff9d195b9671ad45d2cc9f79ecda0900de8ecfb4c864d67ad6a2"
            },
            "downloads": -1,
            "filename": "eventkit-1.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4def44b13603d87f8df009011bc4230f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 31837,
            "upload_time": "2023-12-11T11:41:33",
            "upload_time_iso_8601": "2023-12-11T11:41:33.358729Z",
            "url": "https://files.pythonhosted.org/packages/93/d9/7497d650b69b420e1a913329a843e16c715dac883750679240ef00a921e2/eventkit-1.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "161e0fac4e45d71ace143a2673ec642701c3cd16f833a0e77a57fa6a40472696",
                "md5": "12271e13bcbdf4b08056959463103708",
                "sha256": "99497f6f3c638a50ff7616f2f8cd887b18bbff3765dc1bd8681554db1467c933"
            },
            "downloads": -1,
            "filename": "eventkit-1.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "12271e13bcbdf4b08056959463103708",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 28320,
            "upload_time": "2023-12-11T11:41:35",
            "upload_time_iso_8601": "2023-12-11T11:41:35.339460Z",
            "url": "https://files.pythonhosted.org/packages/16/1e/0fac4e45d71ace143a2673ec642701c3cd16f833a0e77a57fa6a40472696/eventkit-1.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-11 11:41:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "erdewit",
    "github_project": "eventkit",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "numpy",
            "specs": []
        }
    ],
    "lcname": "eventkit"
}
        
Elapsed time: 3.65265s