> Elegant, lightweight **idempotency decorator** for FastAPI.
> Now supporting both **sync** and **async** Redis backends with conflict detection, locking, and automatic response replay.
---
✨ Highlights
- ✅ **Supports `Idempotency-Key` header** for safe re-submissions
- 🔒 **Distributed locking via Redis** to prevent double processing
- ⚡ **Sync & Async backend support**, auto-detected at runtime
- 🧠 **Request signature validation** (method, URL, headers, body)
- 🕒 **Configurable `wait_timeout`** behavior
- 🔁 **Automatic replay** of cached JSON responses
- 🧪 Fully tested for use in payment APIs, order creation, and more
---
🛠 Usage Example
python
from fastapi import FastAPI, Request
from idemptx import idempotent
from idemptx.backend.redis import RedisBackend
app = FastAPI()
backend = RedisBackend()
app.post("/orders")
idempotent(storage_backend=backend)
async def create_order(request: Request):
return {"status": "created"}
> ⚠️ Make sure to include `request: Request` in your endpoint parameters.
---
📦 Install
bash
pip install idemptx
---
📄 Metadata
- **Homepage**: [github.com/pypy-riley/idemptx](https://github.com/pypy-riley/idemptx)
- **License**: MIT
- **Python**: 3.9+
- **Dependencies**: `fastapi`, `redis>=4.2,<6.0`