Typing stubs for retry

0.9.9.20260408 · active · verified Thu Apr 09

The `types-retry` package provides PEP 561 compatible type stubs for the `retry` library (pypi.org/project/retry), enabling static type checking for code that implements retry logic. As an auto-generated part of the `typeshed` project, it receives regular updates to reflect the API of the `retry` library. The current version is 0.9.9.20260408, with releases typically tied to updates in the upstream `retry` library or `typeshed` itself.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to apply the `@retry` decorator to an unreliable function. It configures the decorator to retry specifically on `ConnectionError` exceptions, up to 3 times, with a 2-second delay between attempts. Without `types-retry`, type checkers would have limited understanding of the decorator's effects on the function signature; with it, they can provide more accurate analysis.

import random
from retry import retry
import os

# Example function that might fail
def unreliable_service_call() -> str:
    if random.random() < 0.7:  # 70% chance of failure
        raise ConnectionError("Failed to connect to service!")
    return "Service data retrieved successfully!"

# Decorate the function with retry logic
@retry(exceptions=ConnectionError, tries=3, delay=2000) # Retry 3 times, with 2-second delay
def call_with_retry() -> str:
    print("Attempting service call...")
    return unreliable_service_call()

if __name__ == "__main__":
    try:
        result = call_with_retry()
        print(result)
    except Exception as e:
        print(f"All retry attempts failed: {e}")

view raw JSON →