Skip to main content

Async Rate Limiter (Sliding Window + Lua + Redis)

A Python async rate limiter using Redis and Lua with sliding window algorithm.
Supports retries, exponential backoff, and optional exception handling.


Installation

pip install redis asyncio

Usage

Basic usage with inline function

import asyncio
import redis.asyncio as aioredis
from rate_limit_module import RateLimit  # replace with your module
from rate_limiter.exceptions import RetryLimitReached

redis_client = aioredis.Redis(host='localhost', port=6379, db=0)

rate_limit = RateLimit(
    redis=redis_client,
    limit=5,
    window=10,
    retries=3,
    backoff_ms=200,
    backoff_factor=2.0,
    retry_on_exceptions=(ValueError,),
)

async def my_task():
    print('Task executed.')
    return 42

wrapped = rate_limit(fn=my_task, key='task_key')

try:
    result = await wrapped()
    print(result)
except RetryLimitReached:
    print('All retry attempts exhausted.')

Using as a decorator

rate_limit = RateLimit(
    redis=redis_client,
    limit=3,
    window=5,
    retries=4,
    backoff_ms=100,
    backoff_factor=1.5,
)

@rate_limit(key='decorated_task')
async def my_decorated_task():
    print('Decorated task executed.')
    return 'done'

try:
    await my_decorated_task()
except RetryLimitReached:
    print('Rate limit retry attempts exhausted.')

Exception behavior

After all retries are used without success, the limiter raises RetryLimitReached exception
instead—making it easier to handle failure explicitly in your code.


Features

  • Sliding window rate limiting using Redis + Lua
  • Async-friendly
  • Retries with exponential backoff configurable
  • Optional exception-based retry logic
  • Raises RetryLimitReached when retry attempts are exhausted
  • Supports both inline wrapper and decorator syntax

License

MIT License

Metadata

Release files for rate-limiter-decorator 0.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rate-limiter-decorator 0.0.8
File Size Uploaded Provenance Actions
rate_limiter_decorator-0.0.8.tar.gz 3.4 kB Without provenance Details for rate_limiter_decorator-0.0.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rate-limiter-decorator 0.0.8
File Interpreter ABI Platform Actions
rate_limiter_decorator-0.0.8-py3-none-any.whl Python 3 none any Details for rate_limiter_decorator-0.0.8-py3-none-any.whl

Total release size: 7.3 kB

Release files / rate_limiter_decorator-0.0.8.tar.gz

Download URL rate_limiter_decorator-0.0.8.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
86ea01adc450acef55d20acbc0b82e9760f958e7468caaaf425ff01ad80654bb
BLAKE2b-256 checksum
How to use checksums
75ca16583e8756a1149b70a638809098b28ce27e97cac28b31e257178cb9beaa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.2 CPython/3.12.9 Linux/6.8.0-55-generic

Release files / rate_limiter_decorator-0.0.8-py3-none-any.whl

Download URL rate_limiter_decorator-0.0.8-py3-none-any.whl
Size 4.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
80a236b39f9a7702454efe06240c8042276026ff097ebc7140144db0fb7bbd25
BLAKE2b-256 checksum
How to use checksums
58dc7115e5bd23a869360533ef04597585a3e2dd2ca369e55021d873c9c3575a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.2 CPython/3.12.9 Linux/6.8.0-55-generic

Security for rate-limiter-decorator 0.0.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page