[](https://travis-ci.org/angstwad/trythatagain)
This provides decorators for super simple function/method call retries when an exception is raised.
## Installation
```bash
pip install trythatagain
```
## Examples
Here's a simple use case: querying the AWS API, knowing you might hit API limits.
```python
from trythatagain import retry
@retry
def find_ebs_volumes(unattached=True, no_snapshots=True):
...
try:
find_ebs_volumes()
except CaughtException as e:
print('Failed to list EBS volumes')
print(e.__cause__)
```
This will retry calling `func` three times. If was not successful in calling the function without an exception, it will re-raise the exception as `CaughtException`, with the original exception available at the attribute `__cause__`.
Retry as many times as times as necessary:
```python
from trythatagain import retry
@retry(retries=5)
def try_five_times():
raise Exception('This always fails')
@retry(retries=0)
def retry_forever():
raise Exception('Terrible waste of CPU cycles')
```
Raise immediately on specific exceptions:
```python
@retry(raise_for=ValueError)
def update_cache():
...
```
Suppress re-raising exceptions:
```python
@retry(reraise=False)
def reload_user_data():
...
```
There's also exponential and linear backoff retries things like cooling down after hitting API limits. In fact, AWS recommends exponential backoff to deal with API limits.
```python
# waits 1 second, then 4, then 9, etc.
@retry_exp_backoff(unit=MILLISECONDS)
def update_instance_tags():
...
@retry_linear_backoff(unit=SECONDS)
def scrape_url():
...
```
Custom wait functions are also possible:
```python
def fixed(i, unit):
time.sleep(5 * unit)
@retry(wait_func=fixed, unit=MILLISECONDS)
def func():
...
```
Metadata
Release files for trythatagain 0.1.3
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 | |
|---|---|---|---|---|
| trythatagain-0.1.3.tar.gz | 3.4 kB | Without provenance | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| trythatagain-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
| trythatagain-0.1.3-py2-none-any.whl | Python 2 | none | any | Details |
Total release size: 11.6 kB
Release files / trythatagain-0.1.3.tar.gz
| Download URL | trythatagain-0.1.3.tar.gz |
|---|---|
| Size | 3.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4d28b94140cce0ed20f9ed84126f0488537e292667624bfcfecfd7477785e0e3
|
|
BLAKE2b-256 checksum How to use checksums |
4b61508cda0195ffd2efecce6372ce219e55003f3535daa5b6862ceb427cb8a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / trythatagain-0.1.3-py3-none-any.whl
| Download URL | trythatagain-0.1.3-py3-none-any.whl |
|---|---|
| Size | 4.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7d8970bce2f486f4ae43e56aa263cadd4c00abf209de3696a331799df6fa7c98
|
|
BLAKE2b-256 checksum How to use checksums |
49af544a920564722793833e685d4b1a3f07cf66d8d2ce859cfccb8441d1fc3c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / trythatagain-0.1.3-py2-none-any.whl
| Download URL | trythatagain-0.1.3-py2-none-any.whl |
|---|---|
| Size | 4.1 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
c12d5fd3ed1c2787b6d9efaf9e6c2a3a2fcd3efa7e5321dad8d933e7af41ec67
|
|
BLAKE2b-256 checksum How to use checksums |
584a54d25e0bbe0370d706fa5fac3134f1e2831c221249df80fba44003538f85
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for trythatagain 0.1.3
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.