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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| botobackoff-0.0.2.tar.gz | 4.6 kB | Without provenance | Details for botobackoff-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| botobackoff-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for botobackoff-0.0.2-py3-none-any.whl |
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
|
Security for botobackoff 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.