Skip to main content

Simple retry cient for aiohttp

Project description

This package is similar to Tornado-retry-client.
Python 3.6 or higher.

Install: pip install aiohttp-retry.

Warning

This current version is 2.0. It hasn’t backward compatibility for previous versions.
You still can use v1.2 (pip install aiohttp-retry==1.2), but it is unsupported.

Examples of usage:

from aiohttp_retry import RetryClient, RetryOptions

async def main():
    retry_options = RetryOptions(attempts=1)
    retry_client = RetryClient(raise_for_status=False, retry_options=retry_options)
    async with retry_client.get('https://ya.ru') as response:
        print(response.status)

    await retry_client.close()
from aiohttp_retry import RetryClient

async def main():
    async with RetryClient() as client:
        async with client.get('https://ya.ru') as response:
            print(response.status)
Look tests for more examples.
Be aware: last request returns as it is.

Documentation

RetryClient takes the same arguments as ClientSession[docs]
RetryClient has methods: - get - options - head - post - put - patch - put - delete

They are same as for ClientSession, but take one possible additional argument:

from typing import Optional, Set, Type

class RetryOptions:
    def __init__(
        self,
        attempts: int = 3,  # How many times we should retry
        start_timeout: float = 0.1,  # Base timeout time, then it exponentially grow
        max_timeout: float = 30.0,  # Max possible timeout between tries
        factor: float = 2.0,  # How much we increase timeout each time
        statuses: Optional[Set[int]] = None,  # On which statuses we should retry
        exceptions: Optional[Set[Type[Exception]]] = None,  # On which exceptions we should retry
    )
    ...

You can specify RetryOptions both for RetryClient and it’s methods. RetryOptions in methods override RetryOptions defined in RetryClient constructor.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiohttp_retry-2.1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file aiohttp_retry-2.1-py3-none-any.whl.

File metadata

  • Download URL: aiohttp_retry-2.1-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.9.0

File hashes

Hashes for aiohttp_retry-2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0a8f23ae922b624fec87871a429a8ebd88c8cde2855877337a8a5ea19780833f
MD5 d72367a0063486e7c7a89e4faa9756bf
BLAKE2b-256 f023d5e42341edb51b2ad817c19f8bf5d2ae670641ff9dee500f9df94c562b96

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page