{"id":22621324,"url":"https://github.com/jamesqin-cn/tinyretry","last_synced_at":"2025-10-08T18:11:00.969Z","repository":{"id":57475779,"uuid":"240279503","full_name":"jamesqin-cn/tinyretry","owner":"jamesqin-cn","description":"tinyretry is a python module that provides failure retry encapsulation for the target function","archived":false,"fork":false,"pushed_at":"2020-02-14T06:27:35.000Z","size":6,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-16T09:57:55.504Z","etag":null,"topics":["pip","python2","python3","retry"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jamesqin-cn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-13T14:27:02.000Z","updated_at":"2023-02-06T18:20:22.000Z","dependencies_parsed_at":"2022-09-07T17:12:48.928Z","dependency_job_id":null,"html_url":"https://github.com/jamesqin-cn/tinyretry","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jamesqin-cn/tinyretry","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesqin-cn%2Ftinyretry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesqin-cn%2Ftinyretry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesqin-cn%2Ftinyretry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesqin-cn%2Ftinyretry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamesqin-cn","download_url":"https://codeload.github.com/jamesqin-cn/tinyretry/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesqin-cn%2Ftinyretry/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278990426,"owners_count":26081263,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pip","python2","python3","retry"],"created_at":"2024-12-08T23:07:39.547Z","updated_at":"2025-10-08T18:11:00.946Z","avatar_url":"https://github.com/jamesqin-cn.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tiny Retry\n\n## What is TinyRetry?\ntinyretry is a python module that provides failure retry encapsulation for the target function\n\n## Programming Language\n- python 2.7\n- python 3.7\n\n## Install\n```\npip install tinyretry \n```\n\n## Quick Start\nuse python decorators syntax to wrap the call target\n\n### Case 1: retry until the return code equals to the special value\nWhen we call the function and hope to get the special return code, then we can use `RetryUntilForJson` or `RetryUntilForBool`\n```\nfrom tinyretry import RetryUntilForJson\n\n@RetryUntilForJson(retry_code_key='errno', expected_err_code=0, max_retry_num = 10, retry_interval_sec = 0.1)\ndef DoHttpRequest1():\n    errno = random.randint(0,2)\n    errmsg_arr = ['ok', 'err-timeout', 'err-req-limit']\n    return {\n        \"errno\": errno,\n        \"errmsg\": errmsg_arr[errno]\n    }\n\nclass Test_TinyRetry(unittest.TestCase):\n    def test_RetryUntilForJson(self):\n        for i in range(5):\n            res = DoHttpRequest1()\n            self.assertEqual(res[\"errno\"], 0)\n```\n\nThen you can get the return value from the function `DoHttpRequest1()` which must be successful, the call log like this:\n```\nbogon:tinyretry jamesqin$ python tinyretry_test.py\n2020-02-14 14:03:14,754 - root - INFO - call RetryUntilForJson(DoHttpRequest)(...)\n2020-02-14 14:03:14,754 - root - INFO -     Get expected error code 0\n2020-02-14 14:03:14,754 - root - INFO - call RetryUntilForJson(DoHttpRequest)(...)\n2020-02-14 14:03:14,754 - root - INFO -     Error code 2 was found, retry 1\n2020-02-14 14:03:14,859 - root - INFO -     Get expected error code 0\n2020-02-14 14:03:14,860 - root - INFO - call RetryUntilForJson(DoHttpRequest)(...)\n2020-02-14 14:03:14,860 - root - INFO -     Error code 1 was found, retry 1\n2020-02-14 14:03:14,964 - root - INFO -     Error code 1 was found, retry 2\n2020-02-14 14:03:15,070 - root - INFO -     Error code 1 was found, retry 3\n2020-02-14 14:03:15,172 - root - INFO -     Error code 2 was found, retry 4\n2020-02-14 14:03:15,278 - root - INFO -     Get expected error code 0\n2020-02-14 14:03:15,278 - root - INFO - call RetryUntilForJson(DoHttpRequest)(...)\n2020-02-14 14:03:15,278 - root - INFO -     Error code 2 was found, retry 1\n2020-02-14 14:03:15,381 - root - INFO -     Error code 1 was found, retry 2\n2020-02-14 14:03:15,482 - root - INFO -     Error code 1 was found, retry 3\n2020-02-14 14:03:15,586 - root - INFO -     Error code 1 was found, retry 4\n2020-02-14 14:03:15,692 - root - INFO -     Error code 2 was found, retry 5\n2020-02-14 14:03:15,794 - root - INFO -     Get expected error code 0\n2020-02-14 14:03:15,794 - root - INFO - call RetryUntilForJson(DoHttpRequest)(...)\n2020-02-14 14:03:15,794 - root - INFO -     Get expected error code 0\n.\n----------------------------------------------------------------------\nRan 1 test in 1.040s\n\nOK\n```\n\n### Case 2: while the return code equals to the special value, we will retry\nWhen we call the function and hope to skip the special return code, then we can use `RetryWhileForJson` or `RetryWhileForBool`\n```\nfrom tinyretry import RetryWhileForJson\n\n@RetryWhileForJson(retry_code_key='errno', not_expected_err_code=2, max_retry_num = 10, retry_interval_sec = 0.1)\ndef DoHttpRequest2():\n    errno = random.randint(0,2)\n    errmsg_arr = ['ok', 'err-timeout', 'err-req-limit']\n    return {\n        \"errno\": errno,\n        \"errmsg\": errmsg_arr[errno]\n    }\n\nclass Test_TinyRetry(unittest.TestCase):\n    def test_RetryWhileForJson(self):\n        for i in range(5):\n            res = DoHttpRequest2()\n            self.assertNotEqual(res[\"errno\"], 2)\n```\n\nthen call log look like this:\n```\n2020-02-14 14:13:30,708 - root - INFO - call RetryWhileForJson(DoHttpRequest2)(...)\n2020-02-14 14:13:30,708 - root - INFO -     Error code 2 was found, retry 1\n2020-02-14 14:13:30,810 - root - INFO -     Error code 2 was found, retry 2\n2020-02-14 14:13:30,912 - root - INFO -     Error code 2 was found, retry 3\n2020-02-14 14:13:31,013 - root - INFO -     Error code 2 was found, retry 4\n2020-02-14 14:13:31,117 - root - INFO -     Error code 2 was found, retry 5\n2020-02-14 14:13:31,222 - root - INFO -     Get not expected error code 1\n2020-02-14 14:13:31,222 - root - INFO - call RetryWhileForJson(DoHttpRequest2)(...)\n2020-02-14 14:13:31,222 - root - INFO -     Get not expected error code 0\n2020-02-14 14:13:31,222 - root - INFO - call RetryWhileForJson(DoHttpRequest2)(...)\n2020-02-14 14:13:31,222 - root - INFO -     Error code 2 was found, retry 1\n2020-02-14 14:13:31,324 - root - INFO -     Get not expected error code 0\n2020-02-14 14:13:31,324 - root - INFO - call RetryWhileForJson(DoHttpRequest2)(...)\n2020-02-14 14:13:31,324 - root - INFO -     Error code 2 was found, retry 1\n2020-02-14 14:13:31,426 - root - INFO -     Error code 2 was found, retry 2\n2020-02-14 14:13:31,529 - root - INFO -     Get not expected error code 1\n2020-02-14 14:13:31,529 - root - INFO - call RetryWhileForJson(DoHttpRequest2)(...)\n2020-02-14 14:13:31,529 - root - INFO -     Get not expected error code 1\n```\n\n\n## Other useful retry functions:\nThis package provide two scenarios of failure retries\n- Until scene\n    - RetryUntilForJson()\n    - RetryUntilForBool()\n- while scene\n    - RetryWhileForJson()\n    - RetryWhileForBool()","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesqin-cn%2Ftinyretry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamesqin-cn%2Ftinyretry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesqin-cn%2Ftinyretry/lists"}