Skip to main content

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")

Metadata

Release files for botobackoff 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for botobackoff 0.0.2
File Size Uploaded
botobackoff-0.0.2.tar.gz 4.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for botobackoff 0.0.2
File Interpreter ABI Platform
botobackoff-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 9.6 kB

Release files / botobackoff-0.0.2.tar.gz

Download URL botobackoff-0.0.2.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b2cc660eb0956a335e84ac2d8429ade09cfba0c3ab5d2ab0f7534049bcce96fb
BLAKE2b-256 checksum
How to use checksums
2118e05aab98c9aea211f0a4cc58e4e3fc3dffa8423e16ec944f9f8659bd9a84
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release files / botobackoff-0.0.2-py3-none-any.whl

Download URL botobackoff-0.0.2-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c99cd7794a70a667c5391ed5c92b596abc06e2f0f4261d1f8a0a33f7e4a6aadf
BLAKE2b-256 checksum
How to use checksums
780a34e027734c8a2f4ff9b5c0f71554eeb75480ae07581594ecec52477b03d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page