Skip to content

wkargul/tenacity-rs

tenacity-rs

CI License: MIT

A drop-in replacement for tenacity with a Rust core. Same API, faster retry engine.

  • API-compatible with tenacity — swap the package and your code keeps working.
  • Faster for retry logic (stop/wait/retry checks); see Benchmarks.
  • Async supported via the same decorator and iterator patterns.

Install

pip install tenacity-rs

Drop-in replacement

pip uninstall tenacity
pip install tenacity-rs

Your existing code works without changes (import stays tenacity_rs or you can alias).
→ See MIGRATION.md for a step-by-step guide and any API differences.

Usage

from tenacity_rs import retry, stop_after_attempt, wait_exponential

@retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=4, max=10))
def call_flaky_service():
    ...

API matches tenacity: @retry, stop_after_attempt, stop_after_delay, wait_fixed, wait_exponential, retry_if_exception_type, retry_if_result, callbacks (before, after, before_sleep), and the iterator pattern (for attempt in Retrying(...)).

Benchmarks

We provide a benchmark suite comparing tenacity-rs with pure-Python tenacity:

pip install -e . tenacity
cd benchmarks && python bench.py

See benchmarks/README.md for options (--iterations, --json, --markdown) and how to interpret results. In short: tenacity-rs is typically 2–5× faster on retry logic; when most time is spent in sleep(), both are similar.

Build from source

Requires Rust and a Python environment.

pip install maturin
maturin develop

For Python 3.13+, set before building:

export PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1
maturin develop

Development

pip install -e ".[test]"
pytest tests/ -v

See CONTRIBUTING.md for guidelines and CODE_OF_CONDUCT.md for community standards.

License

MIT.

Acknowledgments

  • tenacity by Julien Danjou and contributors — API and design. tenacity is licensed under the Apache License, Version 2.0. This project is an independent reimplementation; no code from tenacity has been copied.
  • Built with PyO3 and maturin.

About

A drop-in replacement for tenacity with a Rust core. Same API, but Rusty.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors