{ "info": { "author": "deepomatic", "author_email": "support@deepomatic.com", "bugtrack_url": null, "classifiers": [ "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# Table of contents\n\n- [Deepomatic Remote Procedure Call](#deepomatic-remote-procedure-call)\n- [Installation](#installation)\n- [Usage](#usage)\n * [Getting started](#getting-started)\n + [Instanciate client and queues](#instanciate-client-and-queues)\n + [Send recognition request](#send-recognition-request)\n + [Stream and cleanup](#stream-and-cleanup)\n * [Advanced](#advanced)\n + [Shortcuts](#shortcuts)\n + [Image input examples](#image-input-examples)\n- [Bugs](#bugs)\n\n# Deepomatic Remote Procedure Call\n\n[Deepomatic](https://www.deepomatic.com) Remote Procedure Call.\n\nThis remote procedure call has been made to help you interacting with our on-premises inference service.\nYou might also want to use our command line interface [deepomatic-cli](https://pypi.org/project/deepomatic-cli/).\n\n# Installation\n\n# Online\n\n```bash\npip install deepomatic-rpc\n```\n\n# Offline\n\nOn a machine with internet access you will need to download the package and its dependencies with the command below:\n\n```bash\nmkdir deepomatic-rpc\n# --platform force to get the packages compatibles with all OS\npip download --platform any --only-binary=:all: -d ./deepomatic-rpc deepomatic-rpc\n```\n\nThen save the `deepomatic-rpc` directory on the storage device of your choice.\n\nNow retrieve this directory on the offline machine and install the package:\n\n```bash\npip install --no-index --find-links ./deepomatic-rpc ./deepomatic-rpc/deepomatic_rpc-*-py2.py3-none-any.whl\n```\n\n# Usage\n\n## Getting started\n\n### Instanciate client and queues\n\n```python\nfrom deepomatic.rpc.client import Client\n\n# Replace placeholder variables with yours\ncommand_queue_name = 'my_command_queue'\nrecognition_version_id = 123\namqp_url = 'amqp://myuser:mypassword@localhost:5672/myvhost'\n\n# Instanciate client\nclient = Client(amqp_url)\n\n# Do the following for each stream\n\n# Declare lasting command queue\ncommand_queue = client.new_queue(command_queue_name)\n\n# Declare response queue and consumer to get responses\n# consumer is linked to the response_queue\n# If queue_name parameter is provided, will declare a durable queue\n# Otherwise it is an uniq temporary queue.\nresponse_queue, consumer = client.new_consuming_queue()\n\n# Don't forget to cleanup when you are done sending requests !\n```\n\n### Send recognition request\n\n```python\nfrom deepomatic.rpc import v07_ImageInput\nfrom deepomatic.rpc.response import wait\nfrom deepomatic.rpc.helpers.v07_proto import create_images_input_mix, create_recognition_command_mix\n\n# Create a recognition command mix\ncommand_mix = create_recognition_command_mix(recognition_version_id, max_predictions=100, show_discarded=False)\n\n# Create one image input\nimage_input = v07_ImageInput(source='https://static.wamiz.fr/images/animaux/chats/large/bengal.jpg'.encode())\n\n# Wrap it inside a generic input mix\ninput_mix = create_images_input_mix([image_input])\n\n# Send the request\ncorrelation_id = client.command(command_queue_name, response_queue.name, command_mix, input_mix)\n\n# Wait for response, `timeout=float('inf')` or `timeout=-1` for infinite wait, `timeout=None` for non blocking\nresponse = consumer.get(correlation_id, timeout=5)\n\n# get_labelled_output() is a shortcut that give you the corresponding predictions depending on the command mix you used\n# and raise a ServerError in case of error on the worker side. It should cover most cases but if it doesn't fit your needs, see the Response class. You might want to handle result and errors by yourself using `response.to_result_buffer()`.\nlabels = response.get_labelled_output()\npredicted = labels.predicted[0] # Predicted is ordered by score\nprint(\"Predicted label {} with score {}\".format(predicted.label_name, predicted.score))\n# if show_discarded was True, you might want to read `labels.discarded` to see which labels have a low confidence.\n```\n\n### Stream and cleanup\n\nWhen you are done with a stream you should cleanup your consuming queues.\n- If your program stops right after, the consumer get cancelled and the queue will automatically be removed after 2 hours of inactivity (only if the queue is a uniq temporary queue).\n- If your program is a long running job, after 2 hours of inactivity the queue might be removed and the consumer cancelled by the broker, but the client might consider redeclaring both in case of a broker error.\n\nThus calling `client.remove_consuming_queue()` remove the queue and makes sure the consumer is cancelled and not redeclared later:\n\n```python\nclient.remove_consuming_queue(response_queue, consumer)\n```\n\nYou might also want to remove a queue without consumer using:\n\n```python\nclient.remove_queue(queue)\n```\n\nAlso instead of using `new_consuming_queue()` with no queue_name parameter and `remove_consuming_queue()` you might want to use the contextmanager version:\n\n```python\nwith client.tmp_consuming_queue() as (response_queue, consumer):\n # this creates a temporary queue alive for the rest of this scope\n # do your inference requests\n```\n\nIf you don't want to care about the response queue and consumer, we provide a high level class `RPCStream`.\nBy default it saves all correlation_ids so that you can call `get_next_response()` to get responses in the same order that you pushed the requests:\n\n```python\nfrom deepomatic.rpc.helpers.proto import create_v07_images_command\n\nserialized_buffer = create_v07_images_command([image_input], command_mix)\n\nwith client.new_stream(command_queue_name):\n # it internally saves the correlation_id so that it can retrieve responses in order\n # You need to call as many time get_next_response() as send_binary(), or the internal correlation_ids list will keep growing up\n stream.send_binary(serialized_buffer)\n response = stream.get_next_response(timeout=1)\n```\n\nAlso you might want to handle response order by yourself, in this case you can create the stream in the following way:\n```python\n# with keep_response_order=False, the stream will not buffer correlation_ids\nwith client.new_stream(command_queue_name, keep_response_order=False):\n correlation_id = stream.send_binary(serialized_buffer)\n # directly access the stream's consumer to retrieve a specific response\n response = stream.consumer.get(correlation_id, timeout=1)\n```\n\n**IMPORTANT**: If you don't use the with statement, you will have to call `stream.close()` at the end to clean consumer and response queue.\n\n## Advanced\n\n### Shortcuts\n\n* You can avoid calling `create_images_input_mix` and directly sending the image_input list via the method `client.v07_images_command` which will call internally `create_images_input_mix`:\n\n```python\ncorrelation_id = client.v07_images_command(command_queue_name, response_queue.name, [image_input], command_mix)\n```\n\n* Create a workflow command mix. The recognition_version_id is deduced but the command queue name must match the recognition in the workflows.json.\nNote that it doesn't allow to specify `show_discarded` or `max_predictions`:\n\n```python\nfrom deepomatic.rpc.helpers.v07_proto import create_workflow_command_mix\ncommand_mix = create_workflow_command_mix()\n```\n\n* Create an inference command mix; the response will be a raw tensor :\n\n```python\nfrom deepomatic.rpc.helpers.v07_proto import create_inference_command_mix\noutput_tensors = ['prod']\ncommand_mix = create_inference_command_mix(output_tensors)\n```\n\n* Wait multiples correlation ids at once:\n\n```python\nfrom deepomatic.rpc.response import wait_responses\n# Wait for responses, `timeout=float('inf')` or `timeout=-1` for infinite wait\nresponses, pending = wait_responses(consumer, correlation_ids, timeout=10)\n\nprint(responses)\n# will print [(0, response), (1, response), (2, response)]\n# 0, 1, 2 are the position in correlation_ids list in case you want to retrieve their original correlation_id\n# the list is sorted by positions to keep the same order as the correlation_ids list\n# if no timeout reached len(response) == len(correlation_ids)\n\nprint(pending)\n# should be empty if timeout has not been reached\n# otherwise should print a list of correlation_id position that didn't get a response (the list is sorted)\n# If print [3, 5], then correlations_ids[3] and correlation_id[5] didn't get a response on time\n```\n\n### Image input examples\n\n* Create an image input with a bounding box:\n\n```python\nfrom deepomatic.rpc import v07_ImageInput\nfrom deepomatic.rpc import BBox\n# Coordinates between 0 and 1\nbbox = BBox(xmin=0.3, xmax=0.8, ymin=0.1, ymax=0.9)\nimage_input = v07_ImageInput(source='https://static.wamiz.fr/images/animaux/chats/large/bengal.jpg'.encode(),\n bbox=bbox)\n```\n\n* Create an image input with a polygon selection:\n```python\nfrom deepomatic.rpc import v07_ImageInput\nfrom deepomatic.rpc import Point\n# Coordinates between 0 and 1, minimum 3 points needed\npolygon = [Point(x=0.1, y=0.1), Point(x=0.9, y=0.1), Point(x=0.5, y=0.9)]\nimage_input = v07_ImageInput(source='https://static.wamiz.fr/images/animaux/chats/large/bengal.jpg'.encode(),\n polygon=polygon)\n```\n\n* Create an image input from a file on the disk:\n```python\nfrom deepomatic.rpc import v07_ImageInput\nfrom deepomatic.rpc.helpers.proto import binary_source_from_img_file\nbinary_content = binary_source_from_img_file(filename) # Also works if you give a fileobj\nimage_input = v07_ImageInput(source=binary_content)\n```\n\n# Bugs\n\nPlease send bug reports to support@deepomatic.com\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://www.deepomatic.com", "keywords": "", "license": "UNLICENSED", "maintainer": "", "maintainer_email": "", "name": "deepomatic-rpc", "package_url": "https://pypi.org/project/deepomatic-rpc/", "platform": "", "project_url": "https://pypi.org/project/deepomatic-rpc/", "project_urls": { "Homepage": "https://www.deepomatic.com", "Product": "https://www.deepomatic.com" }, "release_url": "https://pypi.org/project/deepomatic-rpc/0.8.2/", "requires_dist": [ "kombu (==4.2.2.post1)", "amqp (==2.4.1)", "protobuf (==3.6.1)" ], "requires_python": "", "summary": "Deepomatic RPC python client", "version": "0.8.2" }, "last_serial": 5896227, "releases": { "0.8.0": [ { "comment_text": "", "digests": { "md5": "d27d1cc8b15bbcb7f8772302bf47a5d5", "sha256": "b703759b913ae160e05733590e006809c672f05020aadaa2c51aebe91917bf74" }, "downloads": -1, "filename": "deepomatic_rpc-0.8.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "d27d1cc8b15bbcb7f8772302bf47a5d5", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 43570, "upload_time": "2019-03-29T18:13:41", "url": "https://files.pythonhosted.org/packages/5d/7a/abebe44a680e19ae6607442c000de7982cda117efdb001b2e1b23700a1d6/deepomatic_rpc-0.8.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "67401cdbc8eb72ecbcd21c930155d452", "sha256": "196c959b6ee300e43fa568e6d0ffe532101eed160cfc0c70474af50cb7177f60" }, "downloads": -1, "filename": "deepomatic-rpc-0.8.0.tar.gz", "has_sig": false, "md5_digest": "67401cdbc8eb72ecbcd21c930155d452", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 32096, "upload_time": "2019-03-29T18:13:44", "url": "https://files.pythonhosted.org/packages/2c/8f/c58ad34d6fe45500e2bf2e49584dc2eb82e68f43b7815f5cf3a96ef453cc/deepomatic-rpc-0.8.0.tar.gz" } ], "0.8.1": [ { "comment_text": "", "digests": { "md5": "c7b6786ce9b28bc1add2aa830996494a", "sha256": "da998167237bfd9d111116c284b8b5b8d6dabb989b66ae33dea0b2b224a7d0e8" }, "downloads": -1, "filename": "deepomatic_rpc-0.8.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "c7b6786ce9b28bc1add2aa830996494a", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 45480, "upload_time": "2019-08-12T16:54:41", "url": "https://files.pythonhosted.org/packages/3f/f7/875980798352bd867a8f847c0ba702287d8f891d1bff1b906ab9d7c61605/deepomatic_rpc-0.8.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "30d5ff9ad8f2e5a0da2fece07438db94", "sha256": "8dd4e3743661be2fb0c159349eafc587167de4982954b8244b3e50295f575d16" }, "downloads": -1, "filename": "deepomatic-rpc-0.8.1.tar.gz", "has_sig": false, "md5_digest": "30d5ff9ad8f2e5a0da2fece07438db94", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 29932, "upload_time": "2019-08-12T16:54:43", "url": "https://files.pythonhosted.org/packages/00/8c/7435c79eac0d557a30f79f0f7d92a82603c6844065779b4b6f068f31dd55/deepomatic-rpc-0.8.1.tar.gz" } ], "0.8.2": [ { "comment_text": "", "digests": { "md5": "f6bbfe49903180c1b36348870f45fcb5", "sha256": "7a4b57530c6b9184772eb3748bf45490dce3952b3964bf3f9a969970b03703df" }, "downloads": -1, "filename": "deepomatic_rpc-0.8.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "f6bbfe49903180c1b36348870f45fcb5", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 45675, "upload_time": "2019-09-27T13:49:41", "url": "https://files.pythonhosted.org/packages/ba/46/3ec990dd5f9bfc81fd6b82207addf140e0680f3a02d09a618562b0d8af66/deepomatic_rpc-0.8.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b55694616f92dab250f56dd30d5e3e48", "sha256": "6d35181cce307b20c0ad80d5afe4a71bce33226f422a2f2c5f272594e9592238" }, "downloads": -1, "filename": "deepomatic-rpc-0.8.2.tar.gz", "has_sig": false, "md5_digest": "b55694616f92dab250f56dd30d5e3e48", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 33258, "upload_time": "2019-09-27T13:49:43", "url": "https://files.pythonhosted.org/packages/65/a2/65bdd15289ff1d96331ca90fbc76b3f5391a440afc24a9bc1225f0ed0a81/deepomatic-rpc-0.8.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f6bbfe49903180c1b36348870f45fcb5", "sha256": "7a4b57530c6b9184772eb3748bf45490dce3952b3964bf3f9a969970b03703df" }, "downloads": -1, "filename": "deepomatic_rpc-0.8.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "f6bbfe49903180c1b36348870f45fcb5", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 45675, "upload_time": "2019-09-27T13:49:41", "url": "https://files.pythonhosted.org/packages/ba/46/3ec990dd5f9bfc81fd6b82207addf140e0680f3a02d09a618562b0d8af66/deepomatic_rpc-0.8.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b55694616f92dab250f56dd30d5e3e48", "sha256": "6d35181cce307b20c0ad80d5afe4a71bce33226f422a2f2c5f272594e9592238" }, "downloads": -1, "filename": "deepomatic-rpc-0.8.2.tar.gz", "has_sig": false, "md5_digest": "b55694616f92dab250f56dd30d5e3e48", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 33258, "upload_time": "2019-09-27T13:49:43", "url": "https://files.pythonhosted.org/packages/65/a2/65bdd15289ff1d96331ca90fbc76b3f5391a440afc24a9bc1225f0ed0a81/deepomatic-rpc-0.8.2.tar.gz" } ] }