{ "info": { "author": "eloylp", "author_email": "eloy@sandboxwebs.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Console", "Intended Audience :: Developers", "Intended Audience :: System Administrators", "License :: Freely Distributable", "Natural Language :: English", "Operating System :: POSIX :: Linux", "Programming Language :: Python :: 3 :: Only", "Topic :: Internet :: WWW/HTTP", "Topic :: Software Development :: Embedded Systems", "Topic :: System :: Networking :: Monitoring" ], "description": "# Scirocco Pyclient\n[![Build Status](https://travis-ci.org/eloylp/scirocco-pyclient.svg?branch=master)](https://travis-ci.org/eloylp/scirocco-pyclient)\n\n\nThis is a handy library to interact with the [scirocco-server](https://github.com/eloylp/scirocco-server) project. If you dont know about it , please read first that project docs.\n\nPlease if you want contribute to this project read [this](CONTRIBUTING.md)\n\n## Installation\n\nThis client library has two main install methods.\n\n#### From source:\n```bash\n git clone https://github.com/eloylp/scirocco-pyclient.git\n python3 setup.py install\n```\n\n#### From pip3:\n```bash\n pip3 install scirocco-pyclient\n```\n\n## Using the client\n\n#### The response object\n\nEvery operation in this client will return the same [response object](sciroccoclient/responses.py)\n, representing the state of the operation as well as the resultant message payload representation.\n\n#### Instantiating the client\n\nYou must instantiate the HTTPClient by passing three params. \nRespectively they are:\n\n* [scirocco-server](https://github.com/eloylp/scirocco-server) endpoint (take care about http/https schema).\n* Your pre-stablished by convention node id (hexadecimal string, will be a mongo Objectid in future). \n* The master auth token for gain access to that scirocco-server instance.\n\n```python\n\nfrom sciroccoclient.httpclient import HTTPClient\n\nscirocco = HTTPClient('http://localhost', 'af123', 'DEFAULT_TOKEN')\n```\n\n#### Pushing messages\nPushing messages is simple as populate [scirocco message object](sciroccoclient/messages.py).\n\n```python\nfrom sciroccoclient.messages import SciroccoMessage\n\n# Preparing our fixed message properties.\n\nmsg = SciroccoMessage()\nmsg.node_destination = 'af123'\n\n# Pushing an object\n\nmsg.payload = {\"type\": \"message\"}\nscirocco.push(msg)\n\n#Pushing a string message payload\n\nmsg.payload = 'message'\nscirocco.push(msg)\n\n# Pushing binary payload\n\nwith open('file.bin', 'rb') as f:\n msg.payload = f.read()\n msg.payload_type = '.bin'\n scirocco.push(msg)\n \n# Pushing scheduled messages, 4 days in future (All in UTC).\nfrom datetime import datetime, timedelta\n\nmsg.payload = 'This is an scheduled message.'\nmsg.scheduled_time = datetime.utcnow() + timedelta(days=4)\nscirocco.push(msg)\n\n```\nSome tips about above code are:\n\n* payload_type property is a 50 characters free field for determining \n how data must be handled in the consumer part. If not setted scirocco will\n populate it with detected mime type.\n* Scheduled messages, are messages that are not available to consumers\n until reaching scheduled_time in time frame. **Warning** , this is not\n the \"consuming time\", only the moment that are marked as \"available\" to\n consumers.\n\n#### Receiving messages\n\nYou will receive messages in the same data type as you send it, except for binary\ntype. You will push binary , and the item is stored as binary , but you will receive \nit in base64 representation.\n\n```python\n\nresponse_object = scirocco.pull()\n\n# print message metadata\nprint(response_object.metadata.__dict__)\n\n# print the message payload.\nprint(response_object.payload)\n```\n\nIf no pending messages the client will return None else, it will return\na response object which contains metadata and payload. The message\nwill change its status to 'processing', so it cannot be accesible by other\n'pull' operation.\n\n##### The on_receive callback \n\nIf you want to make a process that listens for incoming messages, you only need\nto generate a callback function that encapsulates all the logic that must\nprocess each message and create a consumer. \n\nCallback function requirements are:\n\n* Must have two positional arguments\n * First for receiving the client it self for further operations,\n like ack current message.\n * Second argument will be the message received, in the form of [SciroccoMessage](sciroccoclient/messages.py#L6) Object .\n\n```python\n\ndef callback(client, message):\n print(message.payload)\n client.ack(message.metadata.id)\n\nscirocco.on_receive(callback)\n```\n\nAbove example blocks the process and waits for messages, that its contents\nwill be throw into stdout.\n\nIf you do not want this behaviour and want this to be asynchronous you can specify\nat second parameter and let the program continue its execution. This will return the Thread\nobject, (https://docs.python.org/3.6/library/threading.html#thread-objects)\nfor let you control thread execution.\n\n```python\n\non_receive_thread = scirocco.on_receive(callback, True)\nprint(\"Im ready, send me a message.\")\n\n# shutting down the consumer - thread\non_receive_thread.shutdown()\n\n```\n\nBy default, the pull interval is set to 0.5 seconds. **its important** \ntune it according your needs. Remember that , at this time this is not\na real time solution so dont abuse so much the server !\n\n```python\n\nscirocco.on_receive(callback, False, 2) # last param its the pull interval, in this case augmented to 2 seconds.\n\n```\n\nIf you want exiting the program from inside the callback function, you need to use\nthe SciroccoInterruptOnReceiveCallbackError exception.This will shutdown the thread in your custom circunstances.\n \n```python\n\ndef callback(client, message):\n \n # do your stuff here \n \n if message.payload['shutdown']:\n client.ack(message.metadata.id)\n raise SciroccoInterruptOnReceiveCallbackError\n \nscirocco.on_receive(callback)\n```\n \n\n#### Confirming messages (ack operation)\n\nWhen you deal with IPC (inter process communications) or interdependant operations in different processes,\nyou need to mark the message as \"processed\" for further operations\nin other processes.\n\nYou only need to save the id of the message that will be confirmed from\nresponse object (response_object.metadata.id) in its pull operation to confirm\nthe message by id. For example if we want to confirm '5823a70203c123003de4229b' \nmessage id , the code will be :\n\n```python\nscirocco.ack('5823a70203c123003de4229b')\n```\n\n\n#### Reviewing a message\n\nIf you only need to watch the status of a message/es , \ncall for get function, passing as parameter the id of message. Like this.\n\n```python\nscirocco.get('5823a70203c123003de4229b')\n```\n\n\n#### Getting all messages incoming/sended to/by this node\n\nYou optionally can pass a first argument to limit the returned results.\nAnyway, it will be limited by a server side config parameter. \n\n```python\nscirocco.get_all()\n\n# Limiting results by 10 (ordered by creation date)\nscirocco.get_all(10)\n\n```\n\n#### Updating a message\n\nAs first parameter the id of the message. As second parameter the new data\npayload.\n\n```python\nscirocco.update_one(msg_id, new_payload)\n```\n\n#### Deleting a message\n\nYou must specify as first parameter id of the message to be permanent removed\nfrom the system no matters its state. Cannot be undone.\n\n```python\nscirocco.delete_one('5823a70203c123003de4229b')\n```\n\n#### Deleting all messages\n\nDelete from the system all messages incoming/sended to/by this node.\nThis operation only may be executed if you want a total reset of the node and\nits actions. Cannot be undone.\n\n```python\nscirocco.delete_all()\n```\n\n## Running tests\nFor running all tests you will need and instance of [scirocco-server](https://github.com/eloylp/scirocco-server) project up and running at localhost.\n\n```bash\ngit clone https://github.com/eloylp/scirocco-pyclient.git\ncd scirocco-pyclient\npython3 setup.py test\n```", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/eloylp/scirocco-pyclient/tarball/v2.1.3", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/eloylp/scirocco-pyclient", "keywords": null, "license": "GNU AFFERO 3", "maintainer": null, "maintainer_email": null, "name": "scirocco-pyclient", "package_url": "https://pypi.org/project/scirocco-pyclient/", "platform": "any", "project_url": "https://pypi.org/project/scirocco-pyclient/", "project_urls": { "Download": "https://github.com/eloylp/scirocco-pyclient/tarball/v2.1.3", "Homepage": "https://github.com/eloylp/scirocco-pyclient" }, "release_url": "https://pypi.org/project/scirocco-pyclient/v2.1.3/", "requires_dist": null, "requires_python": null, "summary": "Client library for scirocco proyect.", "version": "v2.1.3" }, "last_serial": 2477419, "releases": { "v0.0.4": [ { "comment_text": "built for Linux-3.16.0-4-amd64-x86_64-with-glibc2.9", "digests": { "md5": "b3e9e780734c4be83a341ea3f3793629", "sha256": "5269b41a2e671af4f88986999146281384f94ab7cec14a8d566e3b8ea200a072" }, "downloads": -1, "filename": "scirocco-pyclient-v0.0.4.linux-x86_64.tar.gz", "has_sig": false, "md5_digest": "b3e9e780734c4be83a341ea3f3793629", "packagetype": "bdist_dumb", "python_version": "any", "requires_python": null, "size": 12858, "upload_time": "2016-11-09T17:45:05", "url": "https://files.pythonhosted.org/packages/e9/a9/1be4c484b233b712e84738cc2ca2536fc9acf4f19c1955e8089be3e7bdbb/scirocco-pyclient-v0.0.4.linux-x86_64.tar.gz" }, { "comment_text": "", "digests": { "md5": "c3fc5dc311de8ab988344ca43bc69da1", "sha256": "ecf982f067a0b2c16554c773f25f4aa9effcf91e1171990fadd17b55f0984bfd" }, "downloads": -1, "filename": "scirocco-pyclient-v0.0.4.tar.gz", "has_sig": false, "md5_digest": "c3fc5dc311de8ab988344ca43bc69da1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6080, "upload_time": "2016-11-09T17:45:01", "url": "https://files.pythonhosted.org/packages/fa/68/79e2211650e61c44034fe4b5e428b8948ceedf22139787612c8308b62498/scirocco-pyclient-v0.0.4.tar.gz" } ], "v1.0.0": [ { "comment_text": "built for Linux-3.16.0-4-amd64-x86_64-with-glibc2.9", "digests": { "md5": "81a25a9f720c2aa980eca5c00c474761", "sha256": "56baacad6c3d63b7addb1697a58f8b6da412dd9e67c9cc5494bdf5ebc5439aa5" }, "downloads": -1, "filename": "scirocco-pyclient-v1.0.0.linux-x86_64.tar.gz", "has_sig": false, "md5_digest": "81a25a9f720c2aa980eca5c00c474761", "packagetype": "bdist_dumb", "python_version": "any", "requires_python": null, "size": 14894, "upload_time": "2016-11-12T23:44:41", "url": "https://files.pythonhosted.org/packages/c7/9b/f359d108efb903b66689ec878f77a522d446f4f0ef51ee02cf600e3b0137/scirocco-pyclient-v1.0.0.linux-x86_64.tar.gz" }, { "comment_text": "", "digests": { "md5": "2f8ed52539f9e80da2c33f8481478f11", "sha256": "f243a1f5c0368f9a9ad806d027cad94672ab93ec14fa26e23f20c1853240927d" }, "downloads": -1, "filename": "scirocco-pyclient-v1.0.0.tar.gz", "has_sig": false, "md5_digest": "2f8ed52539f9e80da2c33f8481478f11", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9519, "upload_time": "2016-11-12T23:44:38", "url": "https://files.pythonhosted.org/packages/88/cb/4cd1075f8c88f951bdd635ed755c6c7f8c24cb9eeca89605c9e09599125c/scirocco-pyclient-v1.0.0.tar.gz" } ], "v2.0.0": [ { "comment_text": "built for Linux-3.16.0-4-amd64-x86_64-with-glibc2.9", "digests": { "md5": "7eea6221ceef85f7e5495d00abab43ac", "sha256": "3312b7e75275d7afec7e2f280bfcc999fcde5cd87f1b05b3cc3b9c3e8791983f" }, "downloads": -1, "filename": "scirocco-pyclient-v2.0.0.linux-x86_64.tar.gz", "has_sig": false, "md5_digest": "7eea6221ceef85f7e5495d00abab43ac", "packagetype": "bdist_dumb", "python_version": "any", "requires_python": null, "size": 17627, "upload_time": "2016-11-15T22:08:18", "url": "https://files.pythonhosted.org/packages/76/fc/ae4d98e21f3da704a206ee9f32b04279d2533bfdbcdbf8e3e0c569b384f2/scirocco-pyclient-v2.0.0.linux-x86_64.tar.gz" }, { "comment_text": "", "digests": { "md5": "440f7ccc5045fb92537c394935c588af", "sha256": "0b66b755c3d592841405b429e017e76c3eb410d7748957c31e030e57377e1c9f" }, "downloads": -1, "filename": "scirocco-pyclient-v2.0.0.tar.gz", "has_sig": false, "md5_digest": "440f7ccc5045fb92537c394935c588af", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10182, "upload_time": "2016-11-15T22:08:15", "url": "https://files.pythonhosted.org/packages/e5/e3/366af146698212fa7cc9eda4941fdb0ca3e2ac5def46acac84dfdcc4549a/scirocco-pyclient-v2.0.0.tar.gz" } ], "v2.0.2": [ { "comment_text": "built for Linux-3.16.0-4-amd64-x86_64-with-glibc2.9", "digests": { "md5": "c51ac6729ea8e797061a8c944621336a", "sha256": "80963abafc7b81bd13deb47580ce8766f49a71ad0ae4924153e06f62a6f4e576" }, "downloads": -1, "filename": "scirocco-pyclient-v2.0.2.linux-x86_64.tar.gz", "has_sig": false, "md5_digest": "c51ac6729ea8e797061a8c944621336a", "packagetype": "bdist_dumb", "python_version": "any", "requires_python": null, "size": 17724, "upload_time": "2016-11-19T21:43:55", "url": "https://files.pythonhosted.org/packages/75/aa/443a2f54bdb7a5fde8cb1d5454fa00ea818585559e7cabf67eb3839e5d8c/scirocco-pyclient-v2.0.2.linux-x86_64.tar.gz" }, { "comment_text": "", "digests": { "md5": "03b9443cbe6627e4c115bd08205fa196", "sha256": "65a8ad2cddf84a03ca899e43330896dd91ed9e278566f5f231ff944ba1c403b3" }, "downloads": -1, "filename": "scirocco-pyclient-v2.0.2.tar.gz", "has_sig": false, "md5_digest": "03b9443cbe6627e4c115bd08205fa196", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10410, "upload_time": "2016-11-19T21:43:52", "url": "https://files.pythonhosted.org/packages/de/72/10c5e3edb90f74443ba0f5bb62b3d75ebd293c16807336946a57a6b04d9b/scirocco-pyclient-v2.0.2.tar.gz" } ], "v2.1.3": [ { "comment_text": "built for Linux-3.16.0-4-amd64-x86_64-with-glibc2.9", "digests": { "md5": "080e59bf6d4a0db362515110a30c0635", "sha256": "82946bbc9f9b2236159da07b4a708c44f02646d67786b92529ab908c24b25a46" }, "downloads": -1, "filename": "scirocco-pyclient-v2.1.3.linux-x86_64.tar.gz", "has_sig": false, "md5_digest": "080e59bf6d4a0db362515110a30c0635", "packagetype": "bdist_dumb", "python_version": "any", "requires_python": null, "size": 21826, "upload_time": "2016-11-22T21:51:03", "url": "https://files.pythonhosted.org/packages/dd/86/01bf441e3f98c188e111e8ab776cc5686395a6840bf3f38fc16d12c9f5cc/scirocco-pyclient-v2.1.3.linux-x86_64.tar.gz" }, { "comment_text": "", "digests": { "md5": "c2f21161d5bbef07520690b000cceb99", "sha256": "6d8f5d4bcd6403f017337e57ec003edee3e3778691576902f45d1f9ee1b7d63a" }, "downloads": -1, "filename": "scirocco-pyclient-v2.1.3.tar.gz", "has_sig": false, "md5_digest": "c2f21161d5bbef07520690b000cceb99", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12819, "upload_time": "2016-11-22T21:51:00", "url": "https://files.pythonhosted.org/packages/d6/0e/77d6decd44aca26540fac6ec485cbb8a4a4ea698289b5e2289af8c8e51e9/scirocco-pyclient-v2.1.3.tar.gz" } ] }, "urls": [ { "comment_text": "built for Linux-3.16.0-4-amd64-x86_64-with-glibc2.9", "digests": { "md5": "080e59bf6d4a0db362515110a30c0635", "sha256": "82946bbc9f9b2236159da07b4a708c44f02646d67786b92529ab908c24b25a46" }, "downloads": -1, "filename": "scirocco-pyclient-v2.1.3.linux-x86_64.tar.gz", "has_sig": false, "md5_digest": "080e59bf6d4a0db362515110a30c0635", "packagetype": "bdist_dumb", "python_version": "any", "requires_python": null, "size": 21826, "upload_time": "2016-11-22T21:51:03", "url": "https://files.pythonhosted.org/packages/dd/86/01bf441e3f98c188e111e8ab776cc5686395a6840bf3f38fc16d12c9f5cc/scirocco-pyclient-v2.1.3.linux-x86_64.tar.gz" }, { "comment_text": "", "digests": { "md5": "c2f21161d5bbef07520690b000cceb99", "sha256": "6d8f5d4bcd6403f017337e57ec003edee3e3778691576902f45d1f9ee1b7d63a" }, "downloads": -1, "filename": "scirocco-pyclient-v2.1.3.tar.gz", "has_sig": false, "md5_digest": "c2f21161d5bbef07520690b000cceb99", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12819, "upload_time": "2016-11-22T21:51:00", "url": "https://files.pythonhosted.org/packages/d6/0e/77d6decd44aca26540fac6ec485cbb8a4a4ea698289b5e2289af8c8e51e9/scirocco-pyclient-v2.1.3.tar.gz" } ] }