{ "info": { "author": "Daniel Nachbaur", "author_email": "bbp-open-source@googlegroups.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)", "Operating System :: OS Independent", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# Rockets Python Client\n\n> A small client for [Rockets](../README.md) using [JSON-RPC](https://www.jsonrpc.org) as\n> communication contract over a [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket).\n\n[![Travis CI](https://img.shields.io/travis/BlueBrain/Rockets/master.svg?style=flat-square)](https://travis-ci.org/BlueBrain/Rockets)\n[![Updates](https://pyup.io/repos/github/BlueBrain/Rockets/shield.svg)](https://pyup.io/repos/github/BlueBrain/Rockets/)\n[![Latest version](https://img.shields.io/pypi/v/rockets.svg)](https://pypi.org/project/rockets/)\n[![Python versions](https://img.shields.io/pypi/pyversions/rockets.svg)](https://pypi.org/project/rockets/)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)\n[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/BlueBrain/Rockets.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/BlueBrain/Rockets/context:python)\n\n\n# Table of Contents\n\n* [Installation](#installation)\n* [Usage](#usage)\n * [Connection](#connection)\n * [Notifications](#notifications)\n * [Requests](#requests)\n * [Batching](#batching)\n\n\n### Installation\n----------------\nYou can install this package from [PyPI](https://pypi.org/):\n```bash\npip install rockets\n```\n\n### Usage\n---------\n\n#### `Client` vs. `AsyncClient`\nRockets provides two types of clients to support asychronous and synchronous usage.\n\nThe `AsyncClient` exposes all of its functionality as `async` functions, hence an `asyncio`\n[event loop](https://docs.python.org/3/library/asyncio-eventloop.html) is needed to complete pending\nexecution via `await` or `run_until_complete()`.\n\nFor simplicity, a synchronous `Client` is provided which automagically executes in a synchronous,\nblocking fashion.\n\n#### Connection\nCreate a client and connect:\n```py\nfrom rockets import Client\n\n# client does not connect during __init__;\n# either explicit or automatically on any notify/request/send\nclient = Client('myhost:8080')\n\nclient.connect()\nprint(client.connected())\n```\n\nClose the connection with the socket cleanly:\n```py\nfrom rockets import Client\n\nclient = Client('myhost:8080')\n\nclient.connect()\nclient.disconnect()\nprint(client.connected())\n```\n\n\n#### Server messages\nListen to server notifications:\n```py\nfrom rockets import Client\n\nclient = Client('myhost:8080')\n\nclient.notifications.subscribe(lambda msg: print(\"Got message:\", msg.data))\n```\n\n**NOTE**: The notification object is of type `Notification`.\n\nListen to any server message:\n```py\nfrom rockets import Client\n\nclient = Client('myhost:8080')\n\nclient.ws_observable.subscribe(lambda msg: print(\"Got message:\", msg))\n```\n\n\n#### Notifications\nSend notifications to the server:\n```py\nfrom rockets import Client\n\nclient = Client('myhost:8080')\n\nclient.notify('mymethod', {'ping': True})\n```\n\n\n#### Requests\nMake a synchronous, blocking request:\n```py\nfrom rockets import Client\n\nclient = Client('myhost:8080')\n\nresponse = client.request('mymethod', {'ping': True})\nprint(response)\n```\n\nHandle a request error:\n```py\nfrom rockets import Client, RequestError\n\nclient = Client('myhost:8080')\n\ntry:\n client.request('mymethod')\nexcept RequestError as err:\n print(err.code, err.message)\n```\n\n**NOTE**: Any error that may occur will be a `RequestError`.\n\n\n#### Asynchronous requests\nMake an asynchronous request, using the `AsyncClient` and `asyncio`:\n```py\nimport asyncio\nfrom rockets import AsyncClient\n\nclient = AsyncClient('myhost:8080')\n\nrequest_task = client.async_request('mymethod', {'ping': True})\nasyncio.get_event_loop().run_until_complete(request_task)\nprint(request_task.result())\n```\n\nAlternatively, you can use `add_done_callback()` from the returned `RequestTask` which is called\nonce the request has finished:\n\n```py\nimport asyncio\nfrom rockets import AsyncClient\n\nclient = AsyncClient('myhost:8080')\n\nrequest_task = client.async_request('mymethod', {'ping': True})\nrequest_task.add_done_callback(lambda task: print(task.result()))\nasyncio.get_event_loop().run_until_complete(request_task)\n```\n\nIf the `RequestTask` is not needed, i.e. no `cancel()` or `add_progress_callback()` is desired, use\nthe `request()` coroutine:\n\n```py\nimport asyncio\nfrom rockets import AsyncClient\n\nclient = AsyncClient('myhost:8080')\n\ncoro = client.request('mymethod', {'ping': True})\nresult = asyncio.get_event_loop().run_until_complete(coro)\nprint(result)\n```\n\nIf you are already in an `async` function or in a Jupyter notebook cell, you may use `await` to\nexecute an asynchronous request:\n```py\n# Inside a notebook cell here\nimport asyncio\nfrom rockets import AsyncClient\n\nclient = AsyncClient('myhost:8080')\n\nresult = await client.request('mymethod', {'ping': True})\nprint(result)\n```\n\nCancel a request:\n```py\nfrom rockets import AsyncClient\n\nclient = AsyncClient('myhost:8080')\n\nrequest_task = client.async_request('mymethod')\nrequest_task.cancel()\n```\n\nGet progress updates for a request:\n```py\nfrom rockets import AsyncClient\n\nclient = AsyncClient('myhost:8080')\n\nrequest_task = client.async_request('mymethod')\nrequest_task.add_progress_callback(lambda progress: print(progress))\n```\n\n**NOTE**: The progress object is of type `RequestProgress`.\n\n#### Batching\nMake a batch request:\n```py\nfrom rockets import Client, Request, Notification\n\nclient = Client('myhost:8080')\n\nrequest = Request('myrequest')\nnotification = Notification('mynotify')\nresponses = client.batch([request, notification])\n\nfor response in responses:\n print(response)\n```\n\nCancel a batch request:\n```py\nfrom rockets import AsyncClient\n\nclient = AsyncClient('myhost:8080')\n\nrequest = Request('myrequest')\nnotification = Notification('mynotify')\nrequest_task = client.async_batch([request, notification])\nrequest_task.cancel()\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/BlueBrain/Rockets", "keywords": "rockets,websocket,json-rpc,bbp,BlueBrain", "license": "LGPLv3", "maintainer": "", "maintainer_email": "", "name": "rockets", "package_url": "https://pypi.org/project/rockets/", "platform": "", "project_url": "https://pypi.org/project/rockets/", "project_urls": { "Homepage": "https://github.com/BlueBrain/Rockets" }, "release_url": "https://pypi.org/project/rockets/1.0.2/", "requires_dist": null, "requires_python": "", "summary": "Rockets python client", "version": "1.0.2" }, "last_serial": 5771761, "releases": { "0.1.0.dev0": [ { "comment_text": "", "digests": { "md5": "2df1dddb23167362abb6f1210c7cdb43", "sha256": "dcf1cdabd82dd151ad3ee36145e884855456575947e8213a2fda9f2bfab9d618" }, "downloads": -1, "filename": "rockets-0.1.0.dev0.tar.gz", "has_sig": false, "md5_digest": "2df1dddb23167362abb6f1210c7cdb43", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11369, "upload_time": "2018-10-11T13:19:05", "url": "https://files.pythonhosted.org/packages/b9/77/ac1913eb2f83b3746e064727fe012cb80bd5e2b96c978a7083c9785ae49a/rockets-0.1.0.dev0.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "032a05f217a612f7ea0a083d9f36f4e2", "sha256": "433e64b3a9ec3f2231fc7dc67f9727955a710d5bfb02e0a3a98b57d9315e4cad" }, "downloads": -1, "filename": "rockets-1.0.0.tar.gz", "has_sig": false, "md5_digest": "032a05f217a612f7ea0a083d9f36f4e2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11864, "upload_time": "2019-01-18T10:35:22", "url": "https://files.pythonhosted.org/packages/eb/7d/e656ca67e6a0456dab333784fdc99ff3a1547fee5baedbb3c493124e0cb1/rockets-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "f073fe82f3df172229b3bb69aec1f3f9", "sha256": "18025e7e9656144f1a7a1d59d697abc8520f55646c0c4e83dad5db34f3f87fcd" }, "downloads": -1, "filename": "rockets-1.0.1.tar.gz", "has_sig": false, "md5_digest": "f073fe82f3df172229b3bb69aec1f3f9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11042, "upload_time": "2019-01-18T15:16:47", "url": "https://files.pythonhosted.org/packages/e2/a5/967877cb4568d3cde21f1387aafbdd20dcae837e0a4a7bcde55f3f44a988/rockets-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "8f166d30cf1a4f660c13bf1b73cd4ad6", "sha256": "ce387adec8c6c983173a466ac2184c4e92c4cce3acbf538f9ca5cbaee333d86d" }, "downloads": -1, "filename": "rockets-1.0.2.tar.gz", "has_sig": false, "md5_digest": "8f166d30cf1a4f660c13bf1b73cd4ad6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11842, "upload_time": "2019-07-31T12:56:27", "url": "https://files.pythonhosted.org/packages/f0/ec/561ec49e2ef7e089c5d3088aa48ef2554e3c5d7d5074452d727c06d91596/rockets-1.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8f166d30cf1a4f660c13bf1b73cd4ad6", "sha256": "ce387adec8c6c983173a466ac2184c4e92c4cce3acbf538f9ca5cbaee333d86d" }, "downloads": -1, "filename": "rockets-1.0.2.tar.gz", "has_sig": false, "md5_digest": "8f166d30cf1a4f660c13bf1b73cd4ad6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11842, "upload_time": "2019-07-31T12:56:27", "url": "https://files.pythonhosted.org/packages/f0/ec/561ec49e2ef7e089c5d3088aa48ef2554e3c5d7d5074452d727c06d91596/rockets-1.0.2.tar.gz" } ] }