Skip to main content

A lightweight, zero-dependency retry decorator for synchronous and asynchronous Python functions

Project description

retry_easy

PyPI version Python CI License: MIT

A lightweight, zero-dependency retry decorator for synchronous and asynchronous Python functions.


Features

  • No external runtime dependencies (standard library only)
  • Supports both synchronous and asynchronous functions
  • Configurable retry attempts, backoff, and jitter
  • Fully typed (ParamSpec, TypeVar) and compatible with mypy --strict
  • Safe handling of cancellation (asyncio.CancelledError)
  • Small, readable implementation

Installation

pip install retry_easy

On Python < 3.10, typing-extensions is required for ParamSpec. It is installed automatically.


Quick Start

Synchronous example

from retry_easy import retry
import requests

@retry(attempts=3, delay=1.0, backoff=2.0)
def fetch_data():
    response = requests.get("https://api.example.com/data")
    response.raise_for_status()
    return response.json()

Asynchronous example

import asyncio
from retry_easy import retry

@retry(
    attempts=5,
    delay=0.5,
    exceptions=(ConnectionError, TimeoutError),
    jitter=0.2,
)
async def call_service():
    await asyncio.sleep(0.1)
    raise ConnectionError("Service temporarily unavailable")

API Reference

Parameter Type Default Description
attempts int 3 Number of attempts (≥ 1)
delay float 1.0 Initial delay in seconds (≥ 0)
backoff float 1.0 Multiplier applied after each failure
exceptions tuple[type[Exception], ...] (Exception,) Exceptions that trigger a retry
jitter float 0.0 Random delay added to avoid synchronization

Jitter behavior

wait_time = current_delay + random.uniform(0, jitter)

Why retry_easy?

Use case Typical approach retry_easy
Simple retry logic manual try/except loops decorator
Async support ad-hoc implementations built-in
Lightweight dependency heavy libraries stdlib only
Type safety partial typing full typing

This library targets the common use case: simple, readable retry logic without external dependencies.


Development

git clone https://github.com/undescoreF/retry_easy.git
cd retry_easy

pip install -e ".[dev]"

pytest tests/ -v
mypy src/
ruff check src/ tests/

Contributing

Contributions are welcome.

  1. Fork the repository
  2. Create a branch (feature/my-change)
  3. Commit changes with clear messages
  4. Open a Pull Request
  5. Ensure CI passes (tests, lint, type checks)

License

MIT License. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

retry_easy-0.1.1.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

retry_easy-0.1.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file retry_easy-0.1.1.tar.gz.

File metadata

  • Download URL: retry_easy-0.1.1.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for retry_easy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 35c9a18df704eb1582a02b0b89c4533910ad4245a77e037d127095ab39705c23
MD5 9eb5b22cdd3ecfd6e9638dc32f191519
BLAKE2b-256 5e95e8b9da5e51a2836648d2d91d22a7e561d8d9af38726b510f6c41a4dc07b6

See more details on using hashes here.

File details

Details for the file retry_easy-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: retry_easy-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for retry_easy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dd1d4d1936585e2efd6d706676ebbcfc4bee665f1c76c8cbc41027560b829b53
MD5 31972747da974bf128cf8058d1988d18
BLAKE2b-256 a010c1b6fe18d5dba9210592fa9f9aba54cb00c9991ab771060d3c02a22adfee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page