Stamina

Latest version: v24.2.0

Safety actively analyzes 627763 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 1 of 2

24.2.0

Highlights

This release adds [two handy classes](https://stamina.hynek.me/en/stable/api.html#stamina.RetryingCaller) for the cases when you just want to retry a single function/method call:

python
def do_something_with_url(url, some_kw):
resp = httpx.get(url)
resp.raise_for_status()
...

rc = stamina.RetryingCaller(attempts=5)

rc(httpx.HTTPError, do_something_with_url, f"https://httpbin.org/status/404", some_kw=42)

You can also create a caller with a pre-bound exception type:
bound_rc = rc.on(httpx.HTTPError)

bound_rc(do_something_with_url, f"https://httpbin.org/status/404", some_kw=42)


Both `rc` and `bound_rc` run:

python
do_something_with_url(f"https://httpbin.org/status/404", some_kw=42)


Unfortunately, it's not possible to implement this behavior transparently for async, so you have to use [`AsyncRetryingCaller`](https://stamina.hynek.me/en/stable/api.html#stamina.AsyncRetryingCaller) for async callables.

*Full changelog below!*


Special Thanks

This release would not be possible without my generous sponsors! Thank you to all of you making sustainable maintenance possible! If *you* would like to join them, go to <https://github.com/sponsors/hynek> and check out the sweet perks!


Above and Beyond

[Variomedia AG](https://www.variomedia.de/) ([variomedia](https://github.com/variomedia)), [Tidelift](https://www.tidelift.com/) ([tidelift](https://github.com/tidelift)), [FilePreviews](http://filepreviews.io/) ([filepreviews](https://github.com/filepreviews)), Daniel Fortunov ([asqui](https://github.com/asqui)), Kevin P. Fleming ([kpfleming](https://github.com/kpfleming)), and [Sören Weber](https://www.gedankenspieler.org/) ([SoerenWeber](https://github.com/SoerenWeber)).


Maintenance Sustainers

[Adam Hill](https://adamghill.com) ([adamghill](https://github.com/adamghill)), Dan Groshev ([si14](https://github.com/si14)), Magnus Watn ([magnuswatn](https://github.com/magnuswatn)), [David Cramer](http://cra.mr) ([dcramer](https://github.com/dcramer)), Moving Content AG ([moving-content](https://github.com/moving-content)), [ProteinQure](https://proteinqure.com/) ([ProteinQure](https://github.com/ProteinQure)), Jesse Snyder ([jessesnyder](https://github.com/jessesnyder)), [Rivo Laks](https://rivolaks.com) ([rivol](https://github.com/rivol)), [Ionel Cristian Mărieș](https://blog.ionelmc.ro) ([ionelmc](https://github.com/ionelmc)), [The Westervelt Company](https://westervelt.com) ([westerveltco](https://github.com/westerveltco)), Philippe Galvan ([PhilippeGalvan](https://github.com/PhilippeGalvan)), [Birk Jernström](https://polar.sh) ([birkjernstrom](https://github.com/birkjernstrom)), [Tim Schilling](https://www.better-simple.com) ([tim-schilling](https://github.com/tim-schilling)), Chris Withers ([cjw296](https://github.com/cjw296)), [Christopher Dignam](https://christopher.xyz) ([chdsbd](https://github.com/chdsbd)), [Stefan Hagen](https://stefan-hagen.website) ([sthagen](https://github.com/sthagen)), [Sławomir Ehlert](https://slafs.net) ([slafs](https://github.com/slafs)), Mostafa Khalil ([khadrawy](https://github.com/khadrawy)), [Filip Mularczyk](https://fmularczyk.pl) ([mukiblejlok](https://github.com/mukiblejlok)), [Mike Fiedler](https://mike.fiedler.me) ([miketheman](https://github.com/miketheman)), and [Michel Vittória](https://www.linkedin.com/in/michelvittoria/) ([michelvittoria](https://github.com/michelvittoria)).

Not to forget 5 more amazing humans who chose to be generous but anonymous!


Full Changelog

Added

- `stamina.RetryingCaller` and `stamina.AsyncRetryingCaller` that allow even easier retries of single callables: `stamina.RetryingCaller(attempts=5).on(ValueError)(do_something, "foo", bar=42)` and `stamina.RetryingCaller(attempts=5)(ValueError, do_something, "foo", bar=42)` will call `do_something("foo", bar=42)` and retry on `ValueError` up to 5 times.

`stamina.RetryingCaller` and `stamina.AsyncRetryingCaller` take the same arguments as `stamina.retry()`, except for `on` that can be bound separately.

[\56](https://github.com/hynek/stamina/pull/56) [\#57](https://github.com/hynek/stamina/pull/57)

24.1.0

Highlights

This release only fixes one fun bug caused by one missing return statement. If you ever wondered why you successful blocks got retried when you deactivated _stamina_ – wonder no longer.


Special Thanks

This release would not be possible without my generous sponsors! Thank you to all of you making sustainable maintenance possible! If *you* would like to join them, go to <https://github.com/sponsors/hynek> and check out the sweet perks!


Above and Beyond

[Variomedia AG](https://www.variomedia.de/) ([variomedia](https://github.com/variomedia)), [Tidelift](https://www.tidelift.com/) ([tidelift](https://github.com/tidelift)), [FilePreviews](http://filepreviews.io/) ([filepreviews](https://github.com/filepreviews)), Daniel Fortunov ([asqui](https://github.com/asqui)), and Kevin P. Fleming ([kpfleming](https://github.com/kpfleming)).


Maintenance Sustainers

[Adam Hill](https://adamghill.com) ([adamghill](https://github.com/adamghill)), Dan Groshev ([si14](https://github.com/si14)), Magnus Watn ([magnuswatn](https://github.com/magnuswatn)), [David Cramer](http://cra.mr) ([dcramer](https://github.com/dcramer)), Moving Content AG ([moving-content](https://github.com/moving-content)), [ProteinQure](https://proteinqure.com/) ([ProteinQure](https://github.com/ProteinQure)), Jesse Snyder ([jessesnyder](https://github.com/jessesnyder)), [Rivo Laks](https://rivolaks.com) ([rivol](https://github.com/rivol)), [Ionel Cristian Mărieș](https://blog.ionelmc.ro) ([ionelmc](https://github.com/ionelmc)), [The Westervelt Company](https://westervelt.com) ([westerveltco](https://github.com/westerveltco)), Philippe Galvan ([PhilippeGalvan](https://github.com/PhilippeGalvan)), [Birk Jernström](polar.sh) ([birkjernstrom](https://github.com/birkjernstrom)), [Tim Schilling](www.better-simple.com) ([tim-schilling](https://github.com/tim-schilling)), Chris Withers ([cjw296](https://github.com/cjw296)), [Christopher Dignam](https://christopher.xyz) ([chdsbd](https://github.com/chdsbd)), [Stefan Hagen](https://stefan-hagen.website) ([sthagen](https://github.com/sthagen)), [Sławomir Ehlert](slafs.net) ([slafs](https://github.com/slafs)), Mostafa Khalil ([khadrawy](https://github.com/khadrawy)), [Filip Mularczyk](fmularczyk.pl) ([mukiblejlok](https://github.com/mukiblejlok)), and [Mike Fiedler](https://mike.fiedler.me) ([miketheman](https://github.com/miketheman)).

Not to forget 6 more amazing humans who chose to be generous but anonymous!


Full Changelog

Fixed

- *stamina* doesn't retry successful blocks when it's deactivated anymore (yes, you read it right). [\54](https://github.com/hynek/stamina/pull/54)

23.3.0

Highlights

Support for the [Trio](https://trio.readthedocs.io/) async framework!

Special Thanks

This release would not be possible without my generous sponsors! Thank you to all of you making sustainable maintenance possible! If *you* would like to join them, go to <https://github.com/sponsors/hynek> and check out the sweet perks!


Above and Beyond

[Variomedia AG](https://www.variomedia.de/) ([variomedia](https://github.com/variomedia)), [Tidelift](https://www.tidelift.com/) ([tidelift](https://github.com/tidelift)), [FilePreviews](http://filepreviews.io/) ([filepreviews](https://github.com/filepreviews)), Daniel Fortunov ([asqui](https://github.com/asqui)), and Kevin P. Fleming ([kpfleming](https://github.com/kpfleming)).


Maintenance Sustainers

[Adam Hill](https://adamghill.com) ([adamghill](https://github.com/adamghill)), Dan Groshev ([si14](https://github.com/si14)), Magnus Watn ([magnuswatn](https://github.com/magnuswatn)), [David Cramer](http://cra.mr) ([dcramer](https://github.com/dcramer)), Moving Content AG ([moving-content](https://github.com/moving-content)), [ProteinQure](https://proteinqure.com/) ([ProteinQure](https://github.com/ProteinQure)), Jesse Snyder ([jessesnyder](https://github.com/jessesnyder)), [Rivo Laks](https://rivolaks.com) ([rivol](https://github.com/rivol)), [Ionel Cristian Mărieș](https://blog.ionelmc.ro) ([ionelmc](https://github.com/ionelmc)), [The Westervelt Company](https://westervelt.com) ([westerveltco](https://github.com/westerveltco)), Philippe Galvan ([PhilippeGalvan](https://github.com/PhilippeGalvan)), [Birk Jernström](polar.sh) ([birkjernstrom](https://github.com/birkjernstrom)), [Tim Schilling](www.better-simple.com) ([tim-schilling](https://github.com/tim-schilling)), Chris Withers ([cjw296](https://github.com/cjw296)), [Christopher Dignam](https://christopher.xyz) ([chdsbd](https://github.com/chdsbd)), [Stefan Hagen](https://stefan-hagen.website) ([sthagen](https://github.com/sthagen)), [Sławomir Ehlert](slafs.net) ([slafs](https://github.com/slafs)), Mostafa Khalil ([khadrawy](https://github.com/khadrawy)), and [Filip Mularczyk](fmularczyk.pl) ([mukiblejlok](https://github.com/mukiblejlok)).

Not to forget 5 more amazing humans who chose to be generous but anonymous!


Full Changelog

Added

- [Trio](https://trio.readthedocs.io/) support! [\#43](https://github.com/hynek/stamina/pull/43)

23.2.0

Highlights

The highlight of this release are without question [configurable retry hooks](https://stamina.hynek.me/en/stable/instrumentation.html)! You can now freely configure functions that are run whenever a retry is scheduled.

Can't wait to see what kind of third-party integrations y'all come up with – please [show and tell us](https://github.com/hynek/stamina/discussions/new?category=show-and-tell)!

As a bonus, *stamina* now also comes with standard library's `logging` instrumentation out of the box.


If you have praise, comments, or concerns (that aren't outright bugs), head over to [the release discussion](https://github.com/hynek/stamina/discussions/39!)!


Special Thanks

This release would not be possible without my generous sponsors! Thank you to all of you making sustainable maintenance possible! If *you* would like to join them, go to <https://github.com/sponsors/hynek> and check out the sweet perks!


Above and Beyond

[Variomedia AG](https://www.variomedia.de/) (variomedia), [Tidelift](https://www.tidelift.com/) (tidelift), [HiredScore](https://hiredscore.com) (HiredScore), [FilePreviews](http://filepreviews.io/) (filepreviews), Daniel Fortunov (asqui), and Kevin P. Fleming (kpfleming).


Maintenance Sustainers

[Adam Hill](https://adamghill.com) (adamghill), Dan Groshev (si14), Magnus Watn (magnuswatn), [David Cramer](http://cra.mr) (dcramer), Moving Content AG (moving-content), [ProteinQure](https://proteinqure.com/) (ProteinQure), Jesse Snyder (jessesnyder), [Rivo Laks](https://rivolaks.com) (rivol), [Ionel Cristian Mărieș](https://blog.ionelmc.ro) (ionelmc), [The Westervelt Company](https://westervelt.com) (westerveltco), Philippe Galvan (PhilippeGalvan), [Birk Jernström](polar.sh) (birkjernstrom), [Tim Schilling](www.better-simple.com) (tim-schilling), Chris Withers (cjw296), [Christopher Dignam](https://christopher.xyz) (chdsbd), and [Sławomir Ehlert](slafs.net) (slafs).

Not to forget 5 more amazing humans who chose to be generous but anonymous!


Full Changelog

Added

- Instrumentation is now pluggable! You can define your own hooks that are run with retry details whenever a retry is scheduled. The documentation now has a whole chapter on instrumentation. [\37](https://github.com/hynek/stamina/pull/37)

- If *structlog* is not installed, the scheduled retry is now logged using the standard library `logging` module by default. [\35](https://github.com/hynek/stamina/pull/35)

Changed

- Tenacity's internal `AttemptManager` object is no longer exposed to the user. This was an oversight and never documented. `stamina.retry_context()` now yields instances of `stamina.Attempt`. [\22](https://github.com/hynek/stamina/pull/22)

- Initialization of instrumentation is now delayed. This means that if there's no retries, there's no startup overhead from importing *structlog* and *prometheus-client*. [\34](https://github.com/hynek/stamina/pull/34)

- Some key names in *structlog* log messages have been renamed to better reflect their meaning (`slept` → `waited_so_far`, `attempt` → `retry_num`, and `error` → `caused_by`). You can rename them back using *structlog*'s [`structlog.processors.EventRenamer`](https://www.structlog.org/en/stable/api.html#structlog.processors.EventRenamer). [\35](https://github.com/hynek/stamina/pull/35)

23.1.0

Highlights

With this release, *stamina* graduates to becoming a "real" project. It now has [proper documentation](https://stamina.hynek.me/) and a [backwards-compatibility policy](https://stamina.hynek.me/en/stable/security.html).

The other highlights are certainly transparent support for *async* and retrying of **arbitrary code blocks**!

Full changelog can be found below.

Special Thanks

This release would not be possible without my generous sponsors! Thank you to all of you making sustainable maintenance possible! If *you* would like to join them, go to <https://github.com/sponsors/hynek> and check out the sweet perks!


Above and Beyond

[Variomedia AG](https://www.variomedia.de/) (variomedia), [Tidelift](https://www.tidelift.com/) (tidelift), [Sentry](https://sentry.io) (getsentry), [HiredScore](https://hiredscore.com) (HiredScore), [FilePreviews](http://filepreviews.io/) (filepreviews), and Daniel Fortunov (asqui).


Maintenance Sustainers

[Adam Hill](https://adamghill.com) (adamghill), Dan Groshev (si14), Magnus Watn (magnuswatn), [David Cramer](http://cra.mr) (dcramer), Moving Content AG (moving-content), [Stein Magnus Jodal](https://jod.al) (jodal), [ProteinQure](https://proteinqure.com/) (ProteinQure), Jesse Snyder (jessesnyder), [Rivo Laks](https://rivolaks.com) (rivol), [Tom Ballinger](http://ballingt.com/) (thomasballinger), [Ionel Cristian Mărieș](https://blog.ionelmc.ro) (ionelmc), [The Westervelt Company](https://westervelt.com) (westerveltco), Philippe Galvan (PhilippeGalvan), [Birk Jernström](polar.sh) (birkjernstrom), [Tim Schilling](www.better-simple.com) (tim-schilling), Chris Withers (cjw296), [Christopher Dignam](https://christopher.xyz) (chdsbd), [Stefan Hagen](https://stefan-hagen.website) (sthagen), and zorazen (ZoraZen).

Not to forget 3 more amazing humans who chose to be generous but anonymous!


Full Changelog

Added

- Official Python 3.12 support. [\9](https://github.com/hynek/stamina/pull/9)
- Async support. [\10](https://github.com/hynek/stamina/pull/10)
- Retries of arbitrary blocks using (async) `for` loops and context managers. [\12](https://github.com/hynek/stamina/pull/12)
- Proper documentation. [\16](https://github.com/hynek/stamina/pull/16)
- A backwards-compatibility policy.

Changed

- The *timeout*, *wait_initial*, *wait_max*, and *wait_jitter* arguments can now also be of type [`datetime.timedelta`](https://docs.python.org/3/library/datetime.html#datetime.timedelta).

22.2.0

Instrumentation!


Added

- Retries are now instrumented.
If [*prometheus-client*](https://github.com/prometheus/client_python) is installed, retries are counted using the *Prometheus* counter `stamina_retries_total`.
If [*structlog*](https://www.structlog.org/) is installed, they are logged using a *structlog* logger at warning level.
These two instrumentations are *independent* from each other.

Page 1 of 2

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.