Comparing
High-level concurrency and networking framework on top of asyncio or Trio
Retry any Python function with exponential backoff, jitter, and custom stop conditions — three decorator lines replace 30 lines of retry logic.
| Metric | anyio | tenacity |
|---|---|---|
| Ecosystem | Python | Python |
| Difficulty | Beginner | Beginner |
| Weekly downloads | 0 | 5.0M↑ |
| Latest version | v4.13.0 | v8.5.0 |
| Recipes | 1 | 2↑ |
anyio only
Shared
tenacity only
Use anyio when writing an async library or framework that you want to be runtime-agnostic. It's also useful in applications that want trio's structured concurrency model but need to interop with asyncio-based libraries like FastAPI or aiohttp.
Any I/O that can fail transiently: HTTP calls, database queries, queue operations, cloud API calls, file system operations on network drives.
For application code that commits to asyncio (e.g. a FastAPI app), using asyncio directly is simpler — there's no need for the compatibility layer. anyio shines at the library level, not the application level.
Don't retry non-idempotent operations (POST that creates resources) without careful thought. Don't retry errors that won't resolve with time (auth failures, 400 Bad Request).
anyio
tenacity