After much waffling, I’ve just released a new version of a #Python package that I haven’t advertised much until now, but that’s in prod with virtually every of my work projects: https://stamina.hynek.me/

It has a single purpose: to help you write correct retry logic effortlessly.

If you’ve looked at it before: it now has proper docs, support for async, and retries of arbitrary code blocks. And if you wonder what the big deal is, check out the new tutorial: https://stamina.hynek.me/en/latest/tutorial.html

stamina 24.2.0 documentation

@hynek That was timely! I was planning to implement exponential backoff *again*.
@willmcgugan that’s why it’s called exponential: because everybody implements it multiple times
@hynek this looks incredibly useful!
@hynek thank you. Very annoying to get right!
@hynek Is there a pattern to attach it to an https.Client or requests.Session so that all requests to a given url prefix use the same retry logic?
@sullivancolin it doesn’t append itself to the calls themselves so it can’t know. it only knows about functions or code blocks.
@hynek Ah, I was thinking about something like this which uses the Urlib3 Retry object and the http adapter.
@sullivancolin yeah if you need this fine control, you need to use native, more aware tools. IME it's usually not necessary tho.
@hynek very useful, thanks!
@mkennedy Stamina looks like something you might want to cover on @pythonbytes. At least it doesn't show up in your episode search, yet.

@hynek This looks pretty useful, thanks.

For httpx API request retrying I currently use Gracy (https://github.com/guilatrova/gracy) which includes similar ideas and implements API rate limiting at the same time.

For general retrying this looks much better than what I'm currently doing.

GitHub - guilatrova/gracy: Gracy helps you handle failures, logging, retries, throttling, and tracking for all your HTTP interactions.

Gracy helps you handle failures, logging, retries, throttling, and tracking for all your HTTP interactions. - guilatrova/gracy

GitHub
@hynek Aha, it reminds me the https://tenacity.readthedocs.io/ project
Tenacity — Tenacity documentation

@vstinner Maybe because the main page / README mentions it twice? ;)
@hynek Oops, I just had a quick look at the API. I missed the mention of Tenacity on the homepage.