pythonintermediate
Tenacity Retry for Pipeline Resilience
Add exponential backoff retries to flaky data pipeline steps using Tenacity.
pythonPress ⌘/Ctrl + Shift + C to copy
from tenacity import retry, stop_after_attempt, wait_exponential, retry_if_exception_type
import requests
@retry(
stop=stop_after_attempt(5),
wait=wait_exponential(multiplier=1, min=2, max=30),
retry=retry_if_exception_type((requests.ConnectionError, requests.Timeout)),
reraise=True,
)
def fetch_data(url: str) -> dict:
response = requests.get(url, timeout=10)
response.raise_for_status()
return response.json()
data = fetch_data('https://api.example.com/records')
print(len(data))Use Cases
- resilient API calls
- flaky ETL steps
- transient failure handling
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
pythonbeginner
Tenacity Retry with Backoff
Add robust retry logic with exponential backoff, jitter, and conditional retry using the tenacity library.
Best for: Flaky API calls
#retry#tenacity
pythonintermediate
Retry Logic for Data Pipelines
Configurable retry decorator with exponential backoff and jitter for resilient data pipeline tasks.
Best for: Resilient API calls in data pipelines
#retry#resilience
typescriptintermediate
Retry with Exponential Backoff
Retry failed async operations with exponential backoff, jitter, and configurable retry conditions.
Best for: API call resilience
#nodejs#retry
pythonintermediate
Retry Decorator with Exponential Backoff
Generic retry decorator with configurable attempts, exponential backoff, and exception filtering.
Best for: Network request resilience
#decorator#retry