{"id":32178159,"url":"https://github.com/inyutin/aiohttp_retry","last_synced_at":"2026-02-21T12:01:30.190Z","repository":{"id":37458091,"uuid":"230159234","full_name":"inyutin/aiohttp_retry","owner":"inyutin","description":"Simple retry client for aiohttp.","archived":false,"fork":false,"pushed_at":"2026-02-15T18:27:42.000Z","size":93,"stargazers_count":270,"open_issues_count":10,"forks_count":26,"subscribers_count":6,"default_branch":"master","last_synced_at":"2026-02-16T00:49:51.988Z","etag":null,"topics":["aiohttp","backoff","failure","python","retries"],"latest_commit_sha":null,"homepage":"","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/inyutin.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,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-12-25T22:15:56.000Z","updated_at":"2026-02-15T18:27:46.000Z","dependencies_parsed_at":"2024-02-15T08:31:21.442Z","dependency_job_id":null,"html_url":"https://github.com/inyutin/aiohttp_retry","commit_stats":{"total_commits":83,"total_committers":11,"mean_commits":7.545454545454546,"dds":0.3855421686746988,"last_synced_commit":"ba2169891f5b32a5c59e48ca185dd8e68e44ded7"},"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"purl":"pkg:github/inyutin/aiohttp_retry","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inyutin%2Faiohttp_retry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inyutin%2Faiohttp_retry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inyutin%2Faiohttp_retry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inyutin%2Faiohttp_retry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/inyutin","download_url":"https://codeload.github.com/inyutin/aiohttp_retry/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inyutin%2Faiohttp_retry/sbom","scorecard":{"id":492426,"data":{"date":"2025-08-11","repo":{"name":"github.com/inyutin/aiohttp_retry","commit":"1a3bc19e15de202755e5cdf67c1c011aef2926c9"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.3,"checks":[{"name":"Code-Review","score":1,"reason":"Found 3/27 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codespell.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/inyutin/aiohttp_retry/codespell.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/codespell.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/inyutin/aiohttp_retry/codespell.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish-to-pypi.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/inyutin/aiohttp_retry/publish-to-pypi.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish-to-pypi.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/inyutin/aiohttp_retry/publish-to-pypi.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/publish-to-pypi.yml:29: update your workflow using https://app.stepsecurity.io/secureworkflow/inyutin/aiohttp_retry/publish-to-pypi.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/python-package.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/inyutin/aiohttp_retry/python-package.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/python-package.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/inyutin/aiohttp_retry/python-package.yml/master?enable=pin","Warn: pipCommand not pinned by hash: .github/workflows/publish-to-pypi.yml:22","Warn: pipCommand not pinned by hash: .github/workflows/python-package.yml:26","Warn: pipCommand not pinned by hash: .github/workflows/python-package.yml:27","Info:   0 out of   5 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 third-party GitHubAction dependencies pinned","Info:   0 out of   3 pipCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/codespell.yml:1","Warn: no topLevel permission defined: .github/workflows/publish-to-pypi.yml:1","Warn: no topLevel permission defined: .github/workflows/python-package.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Packaging","score":10,"reason":"packaging workflow detected","details":["Info: Project packages its releases by way of GitHub Actions.: .github/workflows/publish-to-pypi.yml:10"],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":0,"reason":"12 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: PYSEC-2023-120 / GHSA-45c4-8wx5-qw6w","Warn: Project is vulnerable to: GHSA-5m98-qgg9-wh84","Warn: Project is vulnerable to: GHSA-7gpw-8wmc-pm8g","Warn: Project is vulnerable to: GHSA-8495-4g3g-x7pr","Warn: Project is vulnerable to: PYSEC-2024-26 / GHSA-8qpw-xqxj-h4r2","Warn: Project is vulnerable to: GHSA-9548-qrrj-x5pj","Warn: Project is vulnerable to: PYSEC-2023-246 / GHSA-gfw2-4jvh-wgfg","Warn: Project is vulnerable to: GHSA-pjjw-qhg8-p2p9","Warn: Project is vulnerable to: PYSEC-2023-250 / GHSA-q3qx-c6g2-7pw2","Warn: Project is vulnerable to: PYSEC-2023-251 / GHSA-qvrw-v9rv-5rjx","Warn: Project is vulnerable to: PYSEC-2021-76 / GHSA-v6wp-4m6f-gcjg","Warn: Project is vulnerable to: PYSEC-2023-247 / GHSA-xx9p-xxvh-7g8j"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 20 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-19T19:31:37.768Z","repository_id":37458091,"created_at":"2025-08-19T19:31:37.768Z","updated_at":"2025-08-19T19:31:37.768Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29680147,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T11:29:27.227Z","status":"ssl_error","status_checked_at":"2026-02-21T11:29:20.292Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["aiohttp","backoff","failure","python","retries"],"created_at":"2025-10-21T20:49:35.583Z","updated_at":"2026-02-21T12:01:30.181Z","avatar_url":"https://github.com/inyutin.png","language":"Python","readme":"# Simple aiohttp retry client\n\nPython 3.7 or higher.\n\n**Install**: `pip install aiohttp-retry`.\n\n[![\"Buy Me A Coffee\"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/inyutin)\n\n\n### Breaking API changes\n- Everything between [2.7.0 - 2.8.3) is yanked.  \nThere is a bug with evaluate_response_callback, it led to infinite retries\n\n- 2.8.0 is incorrect and yanked.\nhttps://github.com/inyutin/aiohttp_retry/issues/79\n\n- Since 2.5.6 this is a new parameter in ```get_timeout``` func called \"response\".  \nIf you have defined your own ```RetryOptions```, you should add this param into it.\nIssue about this: https://github.com/inyutin/aiohttp_retry/issues/59\n\n### Examples of usage:\n```python\nfrom aiohttp_retry import RetryClient, ExponentialRetry\n\nasync def main():\n    retry_options = ExponentialRetry(attempts=1)\n    retry_client = RetryClient(raise_for_status=False, retry_options=retry_options)\n    async with retry_client.get('https://ya.ru') as response:\n        print(response.status)\n        \n    await retry_client.close()\n```\n\n```python\nfrom aiohttp import ClientSession\nfrom aiohttp_retry import RetryClient \n\nasync def main():\n    client_session = ClientSession()\n    retry_client = RetryClient(client_session=client_session)\n    async with retry_client.get('https://ya.ru') as response:\n        print(response.status)\n\n    await client_session.close()\n```\n\n```python\nfrom aiohttp_retry import RetryClient, RandomRetry\n\nasync def main():\n    retry_options = RandomRetry(attempts=1)\n    retry_client = RetryClient(raise_for_status=False, retry_options=retry_options)\n\n    response = await retry_client.get('/ping')\n    print(response.status)\n        \n    await retry_client.close()\n```\n\n```python\nfrom aiohttp_retry import RetryClient\n\nasync def main():\n    async with RetryClient() as client:\n        async with client.get('https://ya.ru') as response:\n            print(response.status)\n```\n\nYou can change parameters between attempts by passing multiple requests params:\n```python\nfrom aiohttp_retry import RetryClient, RequestParams, ExponentialRetry\n\nasync def main():\n    retry_client = RetryClient(raise_for_status=False)\n\n    async with retry_client.requests(\n        params_list=[\n            RequestParams(\n                method='GET',\n                url='https://ya.ru',\n            ),\n            RequestParams(\n                method='GET',\n                url='https://ya.ru',\n                headers={'some_header': 'some_value'},\n            ),\n        ]\n    ) as response:\n        print(response.status)\n        \n    await retry_client.close()\n```\n\nYou can also add some logic, F.E. logging, on failures by using trace mechanic.\n```python\nimport logging\nimport sys\nfrom types import SimpleNamespace\n\nfrom aiohttp import ClientSession, TraceConfig, TraceRequestStartParams\n\nfrom aiohttp_retry import RetryClient, ExponentialRetry\n\n\nhandler = logging.StreamHandler(sys.stdout)\nlogging.basicConfig(handlers=[handler])\nlogger = logging.getLogger(__name__)\nretry_options = ExponentialRetry(attempts=2)\n\n\nasync def on_request_start(\n    session: ClientSession,\n    trace_config_ctx: SimpleNamespace,\n    params: TraceRequestStartParams,\n) -\u003e None:\n    current_attempt = trace_config_ctx.trace_request_ctx['current_attempt']\n    if retry_options.attempts \u003c= current_attempt:\n        logger.warning('Wow! We are in last attempt')\n\n\nasync def main():\n    trace_config = TraceConfig()\n    trace_config.on_request_start.append(on_request_start)\n    retry_client = RetryClient(retry_options=retry_options, trace_configs=[trace_config])\n\n    response = await retry_client.get('https://httpstat.us/503', ssl=False)\n    print(response.status)\n\n    await retry_client.close()\n```\nLook tests for more examples. \\\n**Be aware: last request returns as it is.**  \n**If the last request ended with exception, that this exception will be raised from RetryClient request**\n\n### Documentation\n`RetryClient` takes the same arguments as ClientSession[[docs](https://docs.aiohttp.org/en/stable/client_reference.html)] \\\n`RetryClient` has methods:\n- request\n- get\n- options\n- head\n- post\n- put\n- patch\n- put\n- delete\n\nThey are same as for `ClientSession`, but take one possible additional argument: \n```python\nclass RetryOptionsBase:\n    def __init__(\n        self,\n        attempts: int = 3,  # How many times we should retry\n        statuses: Iterable[int] | None = None,  # On which statuses we should retry\n        exceptions: Iterable[type[Exception]] | None = None,  # On which exceptions we should retry, by default on all\n        retry_all_server_errors: bool = True,  # If should retry all 500 errors or not\n        # a callback that will run on response to decide if retry\n        evaluate_response_callback: EvaluateResponseCallbackType | None = None,\n    ):\n        ...\n\n    @abc.abstractmethod\n    def get_timeout(self, attempt: int, response: Optional[Response] = None) -\u003e float:\n        raise NotImplementedError\n\n```\nYou can specify `RetryOptions` both for `RetryClient` and it's methods. \n`RetryOptions` in methods override `RetryOptions` defined in `RetryClient` constructor.\n\n**Important**: by default all 5xx responses are retried + statuses you specified as ```statuses``` param\nIf you will pass ```retry_all_server_errors=False``` than you can manually set what 5xx errors to retry.\n\nYou can define your own timeouts logic or use: \n- ```ExponentialRetry``` with exponential backoff\n- ```RandomRetry``` for random backoff\n- ```ListRetry``` with backoff you predefine by list\n- ```FibonacciRetry``` with backoff that looks like fibonacci sequence\n- ```JitterRetry``` exponential retry with a bit of randomness\n\n**Important**: you can proceed server response as an parameter for calculating next timeout.  \nHowever this response can be None, server didn't make a response or you have set up ```raise_for_status=True```\nLook here for an example: https://github.com/inyutin/aiohttp_retry/issues/59\n\nAdditionally, you can specify ```evaluate_response_callback```. It receive a ```ClientResponse``` and decide to retry or not by returning a bool.\nIt can be useful, if server API sometimes response with malformed data.\n\n#### Request Trace Context\n`RetryClient` add *current attempt number* to `request_trace_ctx` (see examples, \nfor more info see [aiohttp doc](https://docs.aiohttp.org/en/stable/client_advanced.html#aiohttp-client-tracing)).\n\n### Change parameters between retries\n`RetryClient` also has a method called `requests`. This method should be used if you want to make requests with different params.\n```python\n@dataclass\nclass RequestParams:\n    method: str\n    url: _RAW_URL_TYPE\n    headers: dict[str, Any] | None = None\n    trace_request_ctx: dict[str, Any] | None = None\n    kwargs: dict[str, Any] | None = None\n```\n\n```python\ndef requests(\n    self,\n    params_list: list[RequestParams],\n    retry_options: RetryOptionsBase | None = None,\n    raise_for_status: bool | None = None,\n) -\u003e _RequestContext:\n```\n\nYou can find an example of usage above or in tests.  \nBut basically `RequestParams` is a structure to define params for `ClientSession.request` func.  \n`method`, `url`, `headers` `trace_request_ctx` defined outside kwargs, because they are popular.  \n\nThere is also an old way to change URL between retries by specifying ```url``` as list of urls. Example:\n```python\nfrom aiohttp_retry import RetryClient\n\nretry_client = RetryClient()\nasync with retry_client.get(url=['/internal_error', '/ping']) as response:\n    text = await response.text()\n    assert response.status == 200\n    assert text == 'Ok!'\n\nawait retry_client.close()\n```\n\nIn this example we request ```/interval_error```, fail and then successfully request ```/ping```.\nIf you specify less urls than ```attempts``` number in ```RetryOptions```, ```RetryClient``` will request last url at last attempts.\nThis means that in example above we would request ```/ping``` once again in case of failure.\n\n### Types\n\n`aiohttp_retry` is a typed project. It should be fully compatible with mypy.\n\nIt also introduce one special type:\n```\nClientType = Union[ClientSession, RetryClient]\n```\n\nThis type can be imported by ```from aiohttp_retry.types import ClientType```\n","funding_links":["https://www.buymeacoffee.com/inyutin"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finyutin%2Faiohttp_retry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finyutin%2Faiohttp_retry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finyutin%2Faiohttp_retry/lists"}