Skip to main content

boto3 retry and backoff utility

Project description

botobackoff

botobackoff provides a boto3 client wrapper and function decorator that automatically retries failed boto3 calls with exponential backoff and jitter.

The decorator and client wrapper include options to add additional error codes to catch and retry on and error codes to ignore and fail silently returning None.

Motivation

Boto3 provides limited retry functionality for failed calls. I wanted to create a simple way to retry boto3 calls with exponential backoff and jitter as well as more flexibility as to what errors can be retried or ignored without needing to add additional try/except blocks around boto3 calls.

Installation

install from PyPI: pip install botobackoff

Usage

Example with the client wrapper:

from botobackoff import BotoBackoff

# `BotoBackoff` can be instantiated with a boto3 client or service name
wrapped_client = BotoBackoff("s3", max_retries=5)

print(wrapped_client.list_objects(Bucket="my-bucket"))

Example as context manager:

from botobackoff import BotoBackoff

wrapped_client = BotoBackoff("s3", max_retries=2)

# use `with_options` to change any of the options for the context manager instance
with wrapped_client.with_options(max_retries=5) as client:
    print(client.list_objects(Bucket="my-bucket"))

Example with the decorator:

from botobackoff import botobackoff

import boto3

@botobackoff(max_retries=5)
def list_objects():
    return boto3.client("s3").list_objects(Bucket="my-bucket")

print(list_objects())

The boto3 errors that are retried by default are:

  • ThrottlingException
  • TooManyRequestsException
  • ServiceUnavailableException
  • RequestLimitExceeded
  • RequestThrottled
  • RequestThrottledException
  • ProvisionedThroughputExceededException
  • LimitExceededException
  • EndpointConnectionError
  • ConnectTimeoutError
  • Unavailable
  • InternalFailure
  • InternalError

to add additional errors to retry on use the added_error_codes parameter:

from botobackoff import botobackoff

import boto3

@botobackoff(added_error_codes=["NoSuchBucket"])
def list_objects():
    return boto3.client("s3").list_objects(Bucket="my-bucket")

Project details


Download files

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

Source Distribution

botobackoff-0.0.2.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

botobackoff-0.0.2-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file botobackoff-0.0.2.tar.gz.

File metadata

  • Download URL: botobackoff-0.0.2.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for botobackoff-0.0.2.tar.gz
Algorithm Hash digest
SHA256 b2cc660eb0956a335e84ac2d8429ade09cfba0c3ab5d2ab0f7534049bcce96fb
MD5 69b3f2cc5bc184c7c4e3ed95eed1d71a
BLAKE2b-256 2118e05aab98c9aea211f0a4cc58e4e3fc3dffa8423e16ec944f9f8659bd9a84

See more details on using hashes here.

File details

Details for the file botobackoff-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: botobackoff-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for botobackoff-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c99cd7794a70a667c5391ed5c92b596abc06e2f0f4261d1f8a0a33f7e4a6aadf
MD5 66cee73055deac394225833ca353997f
BLAKE2b-256 780a34e027734c8a2f4ff9b5c0f71554eeb75480ae07581594ecec52477b03d0

See more details on using hashes here.

Supported by

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