python-resilience

Implement retry logic, timeouts, and fault-tolerant decorators for Python services.

Updated Apr 13, 2026
One-click install
npx skills add https://github.com/scoots31/engineering-playbook --skill python-resilience-scoots31
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-resilience
Source: https://github.com/scoots31/engineering-playbook/tree/main/references/python-resilience
Command: npx skills add https://github.com/scoots31/engineering-playbook --skill python-resilience-scoots31

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires tenacity, httpx, structlog.

What problem does it solve? Transient network failures, timeouts, and flaky external services cause Python applications to crash or hang unpredictably. This Skill provides proven patterns for retries, exponential backoff, timeouts, and graceful degradation so services survive unreliable dependencies. ## Core Features & Use Cases - Retry with Tenacity: Apply bounded retries with exponential backoff and jitter, retrying only transient exceptions and retryable HTTP status codes like 429, 502, 503, and 504. - Timeout and Resilience Decorators: Build reusable timeout decorators for async functions and stack cross-cutting concerns like tracing, logging, and fail-safe defaults. - Use Case: When calling a third-party payment API that occasionally returns 503 errors, wrap the call with a tenacity retry decorator that retries up to 5 times with jittered backoff and logs every attempt for monitoring. ## Quick Start Add retry logic with exponential backoff to my httpx API call so it retries on timeouts and 503 responses up to 3 times.

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. Combine retry_if_exception_type for network errors with retry_if_result to also retry on transient HTTP status codes like 429, 502, 503, and 504.

What is exponential backoff with jitter in Python?

Exponential backoff increases wait time between retries so recovering services are not overwhelmed, while jitter adds randomness to prevent many clients from retrying simultaneously. Tenacity provides this via wait_exponential_jitter with configurable initial and maximum delays.

Which errors should not be retried in Python?

Never retry permanent errors such as ValueError, TypeError, authentication failures, or HTTP 4xx client errors other than 429. These indicate bugs or invalid requests that will fail identically on every attempt, wasting time and resources.

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

Wrap the coroutine with asyncio.wait_for inside a reusable decorator that accepts a seconds parameter. Apply the decorator to any async function so it raises a timeout error when execution exceeds the configured limit.

Why do retries cause a thundering herd problem?

When many clients fail simultaneously and retry on the same fixed schedule, they hit the recovering service in synchronized waves. Adding jitter randomizes each client's wait time, spreading requests out and giving the service capacity to recover.