How jd/tenacity works
Project type and purpose
• This is an open-source Python library (“tenacity”) whose sole purpose is to provide a flexible, pluggable retrying system for arbitrary callables (sync and async).
• It is not a full-stack app; it’s a library/tool that application code imports, configures via decorators or context managers, and then uses to automatically retry operations under various strategies.
File structure
• Top-level modules and dirs
• tenacity/ ← core package
• tests/ ← unit tests verifying behavior
• doc/, releasenotes/ ← documentation and changelog
• CI config (GitHub Actions, tox.ini) and packaging (setup.py, pyproject.toml, setup.cfg)
• Within tenacity/
• _utils.py ← internal shared utilities
• retry.py ← core retry engine (Retrying class, retry decorator)
• stop.py ← pluggable stop strategies (stop after attempts, stop after delay)
• wait.py ← wait strategies (fixed, exponential backoff, jitter)
• before.py & after.py ← hooks invoked before sleep / after call
• nap.py ← core sleeping abstraction
• asyncio/ ← mirror modules for async/await environments
• tornadoweb.py ← Tornado IOLoop compatibility layer
• py.typed ← type-checking marker for PEP 561
Extract insights from the README / docs
• The entry point for users is in retry.py (the retry decorator and Retrying class).
• Documentation (doc/source/index.rst) explains configuration of retry, stop, wait, before/after, and integration points (asyncio, Tornado).
• There is emphasis on pluggability: you supply your own callables for stop and wait strategies or use the built-ins.