[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, 1549 Views

I swear by `tenacity` for python retry logic—it’s super flexible and handles all the annoying stuff like backoff and jitter out of the box.

You can tweak it to stop after X attempts, add exponential delays, or even random jitter to avoid thundering herds.

For example:
```python
from tenacity import retry, stop_after_attempt, wait_exponential

@retry(stop=stop_after_attempt(3), wait=wait_exponential())
def call_api():
# your code here
```

Way cleaner than rolling your own loop IMO.

Messages In This Thread



Users browsing this thread: 1 Guest(s)