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.
pip install tenacity-rspip uninstall tenacity
pip install tenacity-rsYour 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.
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(...)).
We provide a benchmark suite comparing tenacity-rs with pure-Python tenacity:
pip install -e . tenacity
cd benchmarks && python bench.pySee 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.
Requires Rust and a Python environment.
pip install maturin
maturin developFor Python 3.13+, set before building:
export PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1
maturin developpip install -e ".[test]"
pytest tests/ -vSee CONTRIBUTING.md for guidelines and CODE_OF_CONDUCT.md for community standards.
MIT.
- 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.