python-resilience

Implement retry logic, exponential backoff, timeouts, and fault-tolerant decorators in Python applications.

Updated Apr 23, 2026
One-click install
npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill python-resilience-sanketadlak
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-resilience
Source: https://github.com/SanketAdlak/PDMProjectDesign/tree/main/.agents/skills/python-resilience
Command: npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill python-resilience-sanketadlak

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires tenacity, httpx, structlog.

What problem does it solve? Transient failures like network timeouts, rate limiting, and temporary service outages can crash Python applications or cause cascading failures. This Skill provides proven patterns for building fault-tolerant services that retry intelligently, time out safely, and degrade gracefully. ## Core Features & Use Cases - Retry with Tenacity: Apply automatic retries with exponential backoff, jitter, and bounded attempts using the tenacity library, retrying only transient exceptions and retryable HTTP status codes like 429, 502, 503, and 504. - Timeout and Resilience Decorators: Create reusable timeout decorators for async functions and stack cross-cutting concerns like tracing, logging, and retries separately from business logic. - Fail-Safe Defaults and Dependency Injection: Return default values when non-critical operations fail, and inject loggers, metrics clients, and repositories for testable infrastructure. - Use Case: When building a microservice that calls an external payment API, wrap the HTTP call with combined exception and status-code retries, a 30-second timeout, and retry logging so transient outages don't break checkout flows. ## Quick Start Add retry logic with exponential backoff and jitter to my httpx API call so it retries up to 3 times on connection errors and 503 responses.

Frequently Asked Questions about python-resilience

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add retry logic to Python HTTP requests?

Use the tenacity library's @retry decorator with stop_after_attempt and wait_exponential_jitter on your httpx call. Configure retry_if_exception_type for transient exceptions like ConnectionError and TimeoutError, or retry_if_result for status codes like 429 and 503.

Which errors should I retry in Python applications?

Retry only transient errors such as ConnectionError, TimeoutError, httpx.ConnectTimeout, and HTTP status codes 429, 502, 503, and 504. Never retry ValueError, TypeError, authentication failures, or other 4xx client errors, since these indicate permanent problems.

What is exponential backoff with jitter in tenacity?

Exponential backoff increases wait time between retries so recovering services are not overwhelmed, while jitter adds randomness to prevent many clients from retrying simultaneously. Use wait_exponential_jitter(initial=1, max=30) to combine both behaviors.

How do I add a timeout to an async Python function?

Wrap the coroutine with asyncio.wait_for inside a decorator that accepts a seconds parameter. Apply the decorator to your async function so any execution exceeding the limit raises a timeout instead of hanging indefinitely.

When should I use fail-safe defaults instead of retries?

Use fail-safe defaults for non-critical operations where a degraded result is acceptable, such as returning an empty recommendation list when the suggestion service fails. Retries suit operations that must eventually succeed, while fail-safes keep the main flow running.