{ "info": { "author": "Nikita Tsvetkov", "author_email": "nikitanovosibirsk@yandex.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# rtry\n\n[![License](https://img.shields.io/github/license/nikitanovosibirsk/rtry.svg)](https://github.com/nikitanovosibirsk/rtry)\n[![Drone](https://cloud.drone.io/api/badges/nikitanovosibirsk/rtry/status.svg)](https://cloud.drone.io/nikitanovosibirsk/rtry)\n[![Codecov](https://img.shields.io/codecov/c/github/nikitanovosibirsk/rtry/master.svg)](https://codecov.io/gh/nikitanovosibirsk/rtry)\n[![PyPI](https://img.shields.io/pypi/v/rtry.svg)](https://pypi.python.org/pypi/rtry/)\n[![Python Version](https://img.shields.io/pypi/pyversions/rtry.svg)](https://pypi.python.org/pypi/rtry/)\n\n## Installation\n\n```bash\npip3 install rtry\n```\n\n## Documentation\n\n* [timeout](#timeout)\n * [as context manager](#as-context-manager)\n * [as context manager (silent)](#as-context-manager-silent)\n * [as decorator](#as-decorator)\n * [as argument](#as-argument)\n* [retry](#retry)\n * [attempts](#attempts)\n * [until](#until)\n * [logger](#logger)\n * [delay](#delay)\n * [swallow](#swallow)\n\n---\n\n## Timeout\n\n##### As context manager\n\n```python\nfrom rtry import timeout, CancelledError\n\ntry:\n with timeout(3.0):\n resp = requests.get(\"https://httpbin.org/status/200\")\nexcept CancelledError:\n raise\nelse:\n print(resp)\n```\n\n##### As context manager (silent)\n\n```python\nfrom rtry import timeout, CancelledError\n\nresp = None\nwith timeout(3.0, exception=None):\n resp = requests.get(\"https://httpbin.org/status/200\")\n```\n\n##### As decorator\n\n```python\nfrom rtry import timeout, CancelledError\n\n@timeout(3.0)\ndef fn():\n resp = requests.get(\"https://httpbin.org/status/200\")\n return resp\n\ntry:\n resp = fn()\nexcept CancelledError:\n raise\nelse:\n print(resp)\n```\n\n##### As argument\n\n```python\nfrom rtry import retry, CancelledError\n\n@retry(until=lambda r: r.status_code != 200, timeout=3.0)\ndef fn():\n resp = requests.get(\"https://httpbin.org/status/200\")\n return resp\n\ntry:\n resp = fn()\nexcept CancelledError:\n raise\nelse:\n print(resp)\n```\n\n## Retry\n\n### Attempts\n\n```python\n@retry(attempts=2)\ndef fn():\n resp = requests.get(\"https://httpbin.org/status/500\")\n print(resp)\n assert resp.status_code == 200\n return resp\n\nresp = fn()\n# \n# \n# Traceback:\n# AssertionError\n```\n\n### Until\n\n```python\n@retry(until=lambda r: r.status_code != 200, attempts=2)\ndef fn():\n resp = requests.get(\"https://httpbin.org/status/500\")\n print(resp)\n return resp\n\nresp = fn()\n# \n# \n```\n\n### Logger\n\n##### Simple logger\n\n```python\n@retry(until=lambda r: r.status_code != 200, attempts=2, logger=print)\ndef fn():\n resp = requests.get(\"https://httpbin.org/status/500\")\n return resp\n\nresp = fn()\n# 1 \n# 2 \n```\n\n##### Custom logger\n\n```python\ndef logger(attempt, result_or_exception, decorated):\n logging.info(\"Attempt: %d, Result: %s\", attempt, result_or_exception)\n\n@retry(until=lambda r: r.status_code != 200, attempts=2, logger=logger)\ndef fn():\n resp = requests.get(\"https://httpbin.org/status/500\")\n return resp\n\nresp = fn()\n# INFO:root:Attempt: 1, Result: \n# INFO:root:Attempt: 2, Result: \n```\n\n### Delay\n\n##### Const delay\n\n```python\n@retry(until=lambda r: r.status_code != 200, attempts=2, delay=0.1)\ndef fn():\n resp = requests.get(\"https://httpbin.org/status/500\")\n return resp\n\nstarted_at = time()\nresp = fn()\nended_at = time()\nprint('Elapsed {:.2f}'.format(ended_at - started_at))\n# Elapsed 2.11\n```\n\n##### Custom delay\n\n```python\nfrom math import exp\n\n@retry(until=lambda r: r.status_code != 200, attempts=2, delay=exp)\ndef fn():\n resp = requests.get(\"https://httpbin.org/status/500\")\n return resp\n\nstarted_at = time()\nresp = fn()\nended_at = time()\nprint('Elapsed {:.2f}'.format(ended_at - started_at))\n# Elapsed 11.79\n```\n\n### Swallow\n\n##### Fail on first exception\n\n```python\n@retry(attempts=2, swallow=None, logger=print)\ndef fn():\n resp = requests.get(\"http://127.0.0.1/status/500\")\n return resp\n\ntry:\n resp = fn()\nexcept Exception as e:\n print(e)\n # HTTPConnectionPool(host='127.0.0.1', port=80): Max retries exceeded with url: /status/500\n```\n\n##### Swallow only ConnectionError\n\n```python\nfrom requests.exceptions import ConnectionError\n\n@retry(attempts=2, swallow=ConnectionError, logger=print)\ndef fn():\n resp = requests.get(\"http://127.0.0.1/status/500\")\n return resp\n\ntry:\n resp = fn()\nexcept Exception as e:\n print(e)\n # 1 HTTPConnectionPool(host='127.0.0.1', port=80): Max retries exceeded with url: /status/500\n # 2 HTTPConnectionPool(host='127.0.0.1', port=80): Max retries exceeded with url: /status/500\n # HTTPConnectionPool(host='127.0.0.1', port=80): Max retries exceeded with url: /status/500\n```\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://github.com/nikitanovosibirsk/rtry", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "rtry", "package_url": "https://pypi.org/project/rtry/", "platform": "", "project_url": "https://pypi.org/project/rtry/", "project_urls": { "Homepage": "https://github.com/nikitanovosibirsk/rtry" }, "release_url": "https://pypi.org/project/rtry/1.1.2/", "requires_dist": null, "requires_python": ">=3.5.0", "summary": "The easiest way to retry operations", "version": "1.1.2" }, "last_serial": 5155209, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "10bf910e537f709dcd99b795821871a0", "sha256": "1305ca51a7f0444202ef6d4724f708f36b847ddb70994e8991afdcbe3b683a06" }, "downloads": -1, "filename": "rtry-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "10bf910e537f709dcd99b795821871a0", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6253, "upload_time": "2018-10-30T08:21:41", "url": "https://files.pythonhosted.org/packages/47/e1/b05705b3aac019296d46b95294a110ee495a98556aaa13130caf3e5a0d30/rtry-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "011cf9683c1b83c19b2a5e0fe68b90b6", "sha256": "0b296a5775c6d05d2a6151cd5a627531c0182cd59e832431954fe0dfb4ee7ae1" }, "downloads": -1, "filename": "rtry-1.0.0.tar.gz", "has_sig": false, "md5_digest": "011cf9683c1b83c19b2a5e0fe68b90b6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4378, "upload_time": "2018-10-30T08:21:42", "url": "https://files.pythonhosted.org/packages/04/99/ccb370a50871a84a9269d4782b67554217cb8fe7346e41b3597711d07451/rtry-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "862abd7962de88c73c07a136cd02e572", "sha256": "ff32c8d99ac2ad4a06cd3b9953f3a8f61d0903326aa5fbac5dfa4af8f6f7491b" }, "downloads": -1, "filename": "rtry-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "862abd7962de88c73c07a136cd02e572", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6264, "upload_time": "2018-10-30T11:45:27", "url": "https://files.pythonhosted.org/packages/d0/5c/f9c6d0cc4aabcb5e24c0415907edce987824398ff515082f2ae889210757/rtry-1.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "72509c6f96a608b4838bf64b3d03476b", "sha256": "04771acfa4ad1eab35da9ab0b024ed3e6f637ce9e58595eebe8820ede5fb9006" }, "downloads": -1, "filename": "rtry-1.0.1.tar.gz", "has_sig": false, "md5_digest": "72509c6f96a608b4838bf64b3d03476b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4527, "upload_time": "2018-10-30T11:45:29", "url": "https://files.pythonhosted.org/packages/9f/58/3eb63dcd46bfef7851c836015870ae9d251bd3b6aa516d1487d262ac1af1/rtry-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "f37352cbb29cf4b1d85c0260e036e6c1", "sha256": "74c2823513c5df409652bfbbfd2b9e414e462855a9c0f829531551f970d03fb5" }, "downloads": -1, "filename": "rtry-1.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "f37352cbb29cf4b1d85c0260e036e6c1", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7272, "upload_time": "2018-11-01T07:58:52", "url": "https://files.pythonhosted.org/packages/fa/39/eea543d0b50e76428cc120e99be7cc28c3ab5e4b08aa4294602464e088ef/rtry-1.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "047c3d62c9d68e1f86b40c167cde16fa", "sha256": "0f4062eb1b5f8c6deee5dc22577983291bf2d4ec3779f63902ec695814a86474" }, "downloads": -1, "filename": "rtry-1.0.2.tar.gz", "has_sig": false, "md5_digest": "047c3d62c9d68e1f86b40c167cde16fa", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5202, "upload_time": "2018-11-01T07:58:54", "url": "https://files.pythonhosted.org/packages/7b/2f/eab7b72c5e8aa8dcfe39e4067a1749ccdde755edaf41f2bfcc2b76c65615/rtry-1.0.2.tar.gz" } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "01b01b891e1996f6176680c25bddd874", "sha256": "61f370a3d9ad8b1740569ee02b585344e4a098dd5d5e516c7137591c3fce19ac" }, "downloads": -1, "filename": "rtry-1.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "01b01b891e1996f6176680c25bddd874", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7282, "upload_time": "2018-11-01T09:17:43", "url": "https://files.pythonhosted.org/packages/08/fc/bd259913e1dfce50e3576ce97bceefaff9b465f59cded47a9dad82502acb/rtry-1.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "4a76028a8ebcd27e7f4cd2fe371620d8", "sha256": "8bab263d9ae930b48b4d01a0f73409d1e0474ee00cdd6abf426ae5d3ab24d4d3" }, "downloads": -1, "filename": "rtry-1.0.3.tar.gz", "has_sig": false, "md5_digest": "4a76028a8ebcd27e7f4cd2fe371620d8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5200, "upload_time": "2018-11-01T09:17:46", "url": "https://files.pythonhosted.org/packages/c7/41/1681590f28dc153e6ca53359184e895c6e4f3511a56cba8715998b854146/rtry-1.0.3.tar.gz" } ], "1.0.5": [ { "comment_text": "", "digests": { "md5": "ae63e4cdf9d2eb0194ce0b0eb37d5cd8", "sha256": "725fceec713ddfeb5e729e27a4332f4ceab008c1ffa5e49e7d26af095f897a9c" }, "downloads": -1, "filename": "rtry-1.0.5-py3-none-any.whl", "has_sig": false, "md5_digest": "ae63e4cdf9d2eb0194ce0b0eb37d5cd8", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5.0", "size": 4669, "upload_time": "2019-03-27T08:35:35", "url": "https://files.pythonhosted.org/packages/17/86/3b79165aa1869d3e45bcf7eee5342a2585a80b3c31d943c0d8b0c5b840f8/rtry-1.0.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b66cfff26101bf68190658674ade7ce5", "sha256": "dde4a3c1196ccbd607dac4a215f4571a66a37a218478b33626de3019f3768f67" }, "downloads": -1, "filename": "rtry-1.0.5.tar.gz", "has_sig": false, "md5_digest": "b66cfff26101bf68190658674ade7ce5", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5.0", "size": 3476, "upload_time": "2019-03-27T08:35:37", "url": "https://files.pythonhosted.org/packages/53/0a/b461853fcdbc50d4e830917fdd2cf6f190e25fd24be36072090738a11fdd/rtry-1.0.5.tar.gz" } ], "1.0.6": [ { "comment_text": "", "digests": { "md5": "7c524937b0606fe4ddcaa259ae681835", "sha256": "0b2d7999519fe59d1c28226c128fb268d6b847cca914e215ee9a5da2b9637fbe" }, "downloads": -1, "filename": "rtry-1.0.6-py3-none-any.whl", "has_sig": false, "md5_digest": "7c524937b0606fe4ddcaa259ae681835", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5.0", "size": 4756, "upload_time": "2019-04-03T11:36:59", "url": "https://files.pythonhosted.org/packages/1f/38/e12500a8987be7ba7e4a7a5c38b74ab1a88e63a36db115b6f2d98d20b3ad/rtry-1.0.6-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5e1291e2a7480a217afcc83dc1974ddb", "sha256": "4f8210b9eafd9a790475a211d8705978356c28e46f1aa331881e3d39d41cbd9f" }, "downloads": -1, "filename": "rtry-1.0.6.tar.gz", "has_sig": false, "md5_digest": "5e1291e2a7480a217afcc83dc1974ddb", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5.0", "size": 3537, "upload_time": "2019-04-03T11:37:00", "url": "https://files.pythonhosted.org/packages/28/21/e60fdf5604b8472d25286cac25f7d9b42a4907d72c0d5131d4e0202f91d8/rtry-1.0.6.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "4b5dc840216bb7f1747c153c830aa154", "sha256": "c047bd70a0f29bcd046854ef1cc5a78be81c826fd65b26cdd222a78ae1b8a711" }, "downloads": -1, "filename": "rtry-1.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "4b5dc840216bb7f1747c153c830aa154", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5.0", "size": 6838, "upload_time": "2019-04-16T12:39:03", "url": "https://files.pythonhosted.org/packages/b6/83/a97889a0867582c49a3b5bf80d1e0c38eddb9a1b503bff788e8642a1de24/rtry-1.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d5e5ec1ff3f90ebb5282e0db36d2596c", "sha256": "ee314588dd080e94eeb248a511df1e8a55edd7b8f2389315869c7c2649c5d71d" }, "downloads": -1, "filename": "rtry-1.1.0.tar.gz", "has_sig": false, "md5_digest": "d5e5ec1ff3f90ebb5282e0db36d2596c", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5.0", "size": 4742, "upload_time": "2019-04-16T12:39:04", "url": "https://files.pythonhosted.org/packages/66/da/64cae6b845091a46fd500b01df318cb2d5c8f37171fe3073b29e1fb40616/rtry-1.1.0.tar.gz" } ], "1.1.1": [ { "comment_text": "", "digests": { "md5": "b7b7a153ca629e517b47e31fe6218781", "sha256": "903763fa4955f0c45d6a9b7ab73dbac7fd1ca1dfec0d2900293178d97a373bf3" }, "downloads": -1, "filename": "rtry-1.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "b7b7a153ca629e517b47e31fe6218781", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5.0", "size": 7001, "upload_time": "2019-04-17T12:12:52", "url": "https://files.pythonhosted.org/packages/bf/c6/7e2f1e3860d59025ecbaf8f4fded0317dab43ca38e22fe01fb02647c0867/rtry-1.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b203faed4ec7f10aa3ee00070837ff51", "sha256": "cbf257910ab2b977b362d0b711be89c2f2cd59bf4340e6784faeaac02959d232" }, "downloads": -1, "filename": "rtry-1.1.1.tar.gz", "has_sig": false, "md5_digest": "b203faed4ec7f10aa3ee00070837ff51", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5.0", "size": 5079, "upload_time": "2019-04-17T12:12:53", "url": "https://files.pythonhosted.org/packages/25/1f/bf09ec030dd51079c66f0919474ff1ac2455872559498b379d83d14e6e97/rtry-1.1.1.tar.gz" } ], "1.1.2": [ { "comment_text": "", "digests": { "md5": "4605382f7b43514ba8f2fd24371df6f2", "sha256": "0ac673924e7897e5cb2df94255cdb555c926ff105bed441e51628dc222172d6a" }, "downloads": -1, "filename": "rtry-1.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "4605382f7b43514ba8f2fd24371df6f2", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5.0", "size": 7247, "upload_time": "2019-04-17T13:21:45", "url": "https://files.pythonhosted.org/packages/62/04/d3fe56e0083a6e34a57eb9e1da1905a795d37aa6346bc21d710d99cbb54a/rtry-1.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b18e6667dc0f07df9edb9954bb75db5e", "sha256": "d8f2e3396ff26ecbf58599fa69b7affe199641197fa9dbccf956f893b6a0a7fa" }, "downloads": -1, "filename": "rtry-1.1.2.tar.gz", "has_sig": false, "md5_digest": "b18e6667dc0f07df9edb9954bb75db5e", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5.0", "size": 5232, "upload_time": "2019-04-17T13:21:47", "url": "https://files.pythonhosted.org/packages/a3/22/c83a8b7e53ccc26b0852b6d92270d2023815eca191c324ed969c44f48381/rtry-1.1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4605382f7b43514ba8f2fd24371df6f2", "sha256": "0ac673924e7897e5cb2df94255cdb555c926ff105bed441e51628dc222172d6a" }, "downloads": -1, "filename": "rtry-1.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "4605382f7b43514ba8f2fd24371df6f2", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5.0", "size": 7247, "upload_time": "2019-04-17T13:21:45", "url": "https://files.pythonhosted.org/packages/62/04/d3fe56e0083a6e34a57eb9e1da1905a795d37aa6346bc21d710d99cbb54a/rtry-1.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b18e6667dc0f07df9edb9954bb75db5e", "sha256": "d8f2e3396ff26ecbf58599fa69b7affe199641197fa9dbccf956f893b6a0a7fa" }, "downloads": -1, "filename": "rtry-1.1.2.tar.gz", "has_sig": false, "md5_digest": "b18e6667dc0f07df9edb9954bb75db5e", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5.0", "size": 5232, "upload_time": "2019-04-17T13:21:47", "url": "https://files.pythonhosted.org/packages/a3/22/c83a8b7e53ccc26b0852b6d92270d2023815eca191c324ed969c44f48381/rtry-1.1.2.tar.gz" } ] }