{ "info": { "author": "Rami Amar", "author_email": "rami@alooma.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3" ], "description": "# yaretry - Yet Another Retry Library\n\nThis is a small python library for wrapping or decorating functions with retrying logic.\n\n## Naive Usage\n\nWrap any function with the default retrying logic:\n\n```python\n\nimport yaretry\n\n...\n\nretrying_f = yaretry.wrap(f)\nres = retrying_f(call, with, normal, params)\n```\n\nDecorate a function with the default retrying logic:\n\n```python\n\n@yaretry.decorate()\ndef foo(bar):\n pass\n\n\nfoo()\n```\n\nThe default retrying logic will retry calling the function, as long as it raises an instanceof Exception, and will wait an exponentially growing delay between each call. The initial delay will be 1 second, and will double itself every time.\n\n## Customizing Retrying Logic\n\nThe `yaretry` library comes with a Params class, that can be passed to the wrapper and decorator, to customize the retrying logic.\n\nTo add a timeout, measured in seconds:\n\n```\nretrying_f = yaretry.wrap(f, yaretry.Params(timeout=60))\n```\n\nTo add a maximum number of retry attempts:\n\n```\nretrying_f = yaretry.wrap(f, yaretry.Params(max_attempts=10))\n```\n\nTo change the initial delay, and the exponent:\n\n```\nretrying_f = yaretry.wrap(f, yaretry.Params(intial_delay=0.5, exponent=1.2))\n\n# make the delay constant:\nretrying_f = yaretry.wrap(f, yaretry.Params(intial_delay=10, exponent=1))\n```\n\nTo retry in case the function returns False (or a value that, when cast to bool will be False):\n```\n@yaretry.decorate(yaretry.Params(retry_on_false=True))\ndef foo(bar):\n if bar == 1:\n return False # will retry\n elif bar == 2:\n return None # will retry\n elif bar == 3:\n return \"False\" # will *not* retry\n else:\n return True\n```\n\nTo retry only in case of a specific exception or several exceptions:\n```\n@yaretry.decorate(yaretry.Params(allowed_exceptions=(\n MyCustomException,\n LookupError))\ndef foo(bar):\n if bar == 1:\n raise MyCustomException() # will retry\n elif bar == 2:\n raise Exception() # will not retry and raise the Exception\n else:\n raise KeyError() # will retry, as KeyError subclasses LookupError\n```\n\nThe full list of parameters to customize:\n\n- *timeout* - number of seconds after which retrying will stop\n- *max_attempts* - the number of attempts to retry calling the function, before giving up\n- *initial_delay* - the number of seconds to wait before the first retry\n- *max_delay* - the largest delay to wait between retries\n- *exponent* - from retry to retry, the delay is multiplied by this number\n- *logger* - use the provided logger to log when a retry is performed\n- *raise_last_exception* - if True, after retrying is done, the last exception thrown will be raised. if False (the default), the first exception thrown is raised.\n- *retry_on_false* - retry calling the function if it returns a value which `bool(value) == False`\n- *allowed_exceptions* - a tuple of exception classes which, when thrown, the function will be retried\n- *should_retry_cb* - a callback which will be called with the thrown exception. If the callback returns True, the function will be retried\n- *log_level* - a logging.XXXXX log level, indicating which log level to use when logging retry attempts\n\n\n## Some more examples\n\nPass a callback to retry only on HTTP 5xx Errors\n\n```python\nimport yaretry\nimport requests\n\ndef is_server_or_connection_error(ex):\n if isinstance(ex, requests.exceptions.HTTPError):\n return ex.response.status_code >= 500\n if isinstance(ex, requests.exceptions.ConnectionError):\n return True\n return False\n\n\n@yaretry.decorate(yaretry.Params(\n max_attempts=5,\n should_retry_cb=is_server_or_connection_error))\ndef call_api(url):\n res = requests.get(url)\n res.raise_on_failure()\n return res.json()\n```\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/Aloomaio/yaretry", "keywords": "alooma, retry", "license": "", "maintainer": "", "maintainer_email": "", "name": "yaretry", "package_url": "https://pypi.org/project/yaretry/", "platform": "", "project_url": "https://pypi.org/project/yaretry/", "project_urls": { "Homepage": "https://github.com/Aloomaio/yaretry" }, "release_url": "https://pypi.org/project/yaretry/0.1.1/", "requires_dist": null, "requires_python": "", "summary": "Small library for a neat looking retry wrapper", "version": "0.1.1" }, "last_serial": 4062885, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "0037a29dc60724e0a335d985abcb9f66", "sha256": "8474303bd0f4528164f27428e0f3c1a3a759bf4eb298e331d977719b0a8281d9" }, "downloads": -1, "filename": "yaretry-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "0037a29dc60724e0a335d985abcb9f66", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 2478, "upload_time": "2018-07-15T09:45:33", "url": "https://files.pythonhosted.org/packages/a7/11/e3c319d7c091cf93709b1f7dc6042f56988149a51672d095555c2de1e9a2/yaretry-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "156708daaec940f3b6609664284e37bd", "sha256": "e9efd4041947e7b57f7effa870ee57acb06dc29d57da7a69898762dfa02a6a76" }, "downloads": -1, "filename": "yaretry-0.1.0.tar.gz", "has_sig": false, "md5_digest": "156708daaec940f3b6609664284e37bd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3220, "upload_time": "2018-07-15T09:45:34", "url": "https://files.pythonhosted.org/packages/8e/14/433bb6e942e7cc56698999cb1d74d163ae75ee70978e6b8a799620efac98/yaretry-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "6fcc63610700ce84e80c1b94226e7689", "sha256": "77bf58af7709ccd7162086d8c930f9d71cd4b1506ee0a5912a0d26c860d7aae2" }, "downloads": -1, "filename": "yaretry-0.1.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "6fcc63610700ce84e80c1b94226e7689", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 5940, "upload_time": "2018-07-15T11:54:20", "url": "https://files.pythonhosted.org/packages/07/a7/ac63681bb0fd4bc95d227f011cd0e3f70b2cead3f50fd11d604f7be69d0a/yaretry-0.1.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fe3a07a9ea9ba1fbea30c6d77f94c237", "sha256": "2ee5d92a7c1115c0b9be75dc30714f97df5deb9cace90fdee878f9c23d5e20f0" }, "downloads": -1, "filename": "yaretry-0.1.1.tar.gz", "has_sig": false, "md5_digest": "fe3a07a9ea9ba1fbea30c6d77f94c237", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3376, "upload_time": "2018-07-15T11:54:21", "url": "https://files.pythonhosted.org/packages/cd/bb/dcd98e00b8437bc60377c895cebb93834e855ab79ef45aa3c3c410cdf734/yaretry-0.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6fcc63610700ce84e80c1b94226e7689", "sha256": "77bf58af7709ccd7162086d8c930f9d71cd4b1506ee0a5912a0d26c860d7aae2" }, "downloads": -1, "filename": "yaretry-0.1.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "6fcc63610700ce84e80c1b94226e7689", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 5940, "upload_time": "2018-07-15T11:54:20", "url": "https://files.pythonhosted.org/packages/07/a7/ac63681bb0fd4bc95d227f011cd0e3f70b2cead3f50fd11d604f7be69d0a/yaretry-0.1.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fe3a07a9ea9ba1fbea30c6d77f94c237", "sha256": "2ee5d92a7c1115c0b9be75dc30714f97df5deb9cace90fdee878f9c23d5e20f0" }, "downloads": -1, "filename": "yaretry-0.1.1.tar.gz", "has_sig": false, "md5_digest": "fe3a07a9ea9ba1fbea30c6d77f94c237", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3376, "upload_time": "2018-07-15T11:54:21", "url": "https://files.pythonhosted.org/packages/cd/bb/dcd98e00b8437bc60377c895cebb93834e855ab79ef45aa3c3c410cdf734/yaretry-0.1.1.tar.gz" } ] }