[b]"What's the best way to implement python retry for API calls?"[/b] or [b]"How do you handle python retry logic

12 Replies, 1554 Views

I’ve been down this rabbit hole too! Ended up using `backoff` lib because it’s stupid simple and has sane defaults.

Example:
```python
import backoff
import requests

@backoff.on_exception(backoff.expo, requests.exceptions.RequestException, max_tries=3)
def get_data():
return requests.get("https://api.example.com")
```

Exponential backoff is baked in, and you can add jitter if you want.

Messages In This Thread



Users browsing this thread: 1 Guest(s)