Metadata-Version: 2.5
Name: retrydec
Version: 0.1.0
Summary: Smart, zero-dependency retry decorator supporting sync and async functions with jitter.
Author-email: Andrey Egupov <and302014@gmail.com>
License-File: LICENSE.txt
Keywords: async,backend,backoff,decorator,jitter,retry,smart-retry,zero-dependency
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.7.0
Description-Content-Type: text/markdown

# Retrydec - smart, zero-dependency retry decorator for python supporting sync and async functions with jitter.

## 📦Installation
```bash
pip install retrydec
```
## ⚡Quick Start
```python
from retrydec import retry

attempts_num = 0


@retry(attempts=5, delay=0.3)
def example():
    # ↓ Your custom code goes here
    global attempts_num
    attempts_num += 1
    if attempts_num == 3:
        raise TimeoutError("Error: 504") 

```
## ✨Retrydec Features
- No dependencies
- Smart supporting sync and async functions with jitter
- Very easy to use
- Exponential backoff algorithm
- Custom exception filtering 

## 📃Usage
Library import:
```python
from retrydec import retry
```
Initialize and run retry decorator with sync or async functions:
```python
@retry()
```

### Decorator arguments
| Parameter | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| `attempts` | `int` | `1` | Maximumu numbers of  execution attempts. | 
| `delay` | `float` | `1.0` | Base delay between attempts in seconds. |
| `exceptions` | `tuple` | `(Exception)` | Tuple of exceptions to catch and retry. |
| `jitter` | `bool` | `False` | Enables random noise to prevent server stampede. |

**Note: all decorator arguments work the same way for both `async` and `sync` functions.**

#### Base example:
```python
from retrydec import retry
import asyncio

attempts_num = 0
print("----------Sync test----------")


@retry(attempts=5, delay=0.3)
def example():
    global attempts_num
    attempts_num += 1
    print(f"Attempt number: {attempts_num}")
    raise TimeoutError("Error: 504")  # Server error simulation


try:
    example()
except TimeoutError:
    print("Sync test: OK!")
attempts_num = 0
print("----------Async test----------")


@retry(jitter=True, exceptions=(TimeoutError))
async def example():
    global attempts_num
    attempts_num += 1
    print(f"Attempt number: {attempts_num}")
    if attempts_num == 1:
        raise TimeoutError("Error: 504")  # Server error simulation


asyncio.run(example())
print("Async test: OK!")
```

## ❔Why is it convenient?
- **Clean code** It replaces the cumbersome `try-except-while` constructs with a single decorator.
- **Unified API** There is no need to support different tools - retrydec uses a single smart decorator that determines whether a function is `sync` or `async`.
- **Zero dependencies** Provides light weight
- **Safety** The built-in backoff and jitter protect your servers from overload during failures.

## 👦🏻 About the developer
My name is Andrey Egupov, I'm 12 years old. I've been programming for several years. I started in Scratch, now I write in Python, JavaScript, and I'm working with Arduino.
The idea for this project came from a desire to create something that would greatly help developers and fill a gap in the Python ecosystem.

## 📄 License
MIT © 2026 Andrey Egupov