https://github.com/bobthebuidler/eth_retry
Stop transient errors from wasting your time! Provides a decorator to automatically retry calls that fail due to specific transient errors seen in the web3 ecosystem.
https://github.com/bobthebuidler/eth_retry
eth-brownie ethereum evm python python3 web3 web3py
Last synced: 5 months ago
JSON representation
Stop transient errors from wasting your time! Provides a decorator to automatically retry calls that fail due to specific transient errors seen in the web3 ecosystem.
- Host: GitHub
- URL: https://github.com/bobthebuidler/eth_retry
- Owner: BobTheBuidler
- License: mit
- Created: 2022-04-27T22:56:20.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2026-01-21T08:19:35.000Z (5 months ago)
- Last Synced: 2026-01-21T17:32:05.321Z (5 months ago)
- Topics: eth-brownie, ethereum, evm, python, python3, web3, web3py
- Language: Python
- Homepage:
- Size: 2.51 MB
- Stars: 11
- Watchers: 3
- Forks: 1
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Agents: AGENTS.md
Awesome Lists containing this project
README
# eth_retry
> Stop transient errors from wasting your time!
`eth_retry` is a Python library that provides one decorator, `eth_retry.auto_retry`.
`auto_retry` will automatically catch known transient exceptions that are common in the Ethereum/EVM ecosystem and will reattempt to evaluate your decorated function up to `os.environ['MAX_RETRIES']` (default: 10) times.
Supports both synchronous and asynchronous functions.
------------
Covers many common transient errors in the EVM ecosystem, including:
- RPC timeouts
- Block explorer API rate-limiting
- Generic exceptions:
- ConnectionError
- HTTPError
- ReadTimeout
- TimeoutError
- eth-brownie specific errors:
- sqlite3.OperationalError: database is locked
## Installation:
`pip install eth_retry`
or
`pip install git+https://github.com/BobTheBuidler/eth_retry.git`
## Usage:
```
import eth_retry
@eth_retry.auto_retry
def some_function_that_errors_sometimes():
i = 0
am = 1
doing = 2
stuff = 3
return stuff
error_free_result = some_function_that_errors_sometimes()
```
Between attempts, eth_retry will `time.sleep` for a random period between `os.environ['MIN_SLEEP_TIME']` (default: 10) and `os.environ['MAX_SLEEP_TIME']` (default: 20) seconds. The period is randomized to help prevent repetitive rate-limiting issues with parallelism by staggering the retries.
On the `n`th retry, the sleep period is multiplied by `n` so that the target endpoint can cool off in case of rate-limiting.
After `os.environ['MAX_RETRIES']` failures, eth_retry will raise the exception.
## Environment:
```
# Minimum sleep time in seconds. Integer. Defaults to 10.
MIN_SLEEP_TIME=10
# Maximum sleep time in seconds. Integer. Defaults to 20.
MAX_SLEEP_TIME=20
# Maximum number of times to retry. Integer. Defaults to 10.
MAX_RETRIES=10
```