Skip to main content

py-redis-ratelimit version downloads

A simple asynchronous rate limiter based on redis.

Requirements

Installation

pip install py-redis-ratelimit

Examples

Basic example:

from redis.asyncio import Redis
import ratelimit, asyncio

redis = Redis(decode_responses=True)
limiter = ratelimit.RateLimit(
    redis, prefix="api_rate_limit", rate=10, period=60, retry_after=20
)
print(ratelimit.RateLimit.__doc__)  # print RateLimit class docstring


async def do_something():
    await limiter.acquire(
        identifier="do_something_function"
    )  # a unique identifier for the function. This let's RateLimit know what service/resource you are trying to access.
    ...


async def main():
    for x in range(40):
        try:
            print("Calling do_something() for the {}th time".format(x + 1))
            await do_something()
        except ratelimit.FloodWait as e:
            print("Exception:", e.to_dict())
            break


if __name__ == "__main__":
    asyncio.run(main())

Contributing

Pull requests are always welcome!!

License

MIT License

Metadata

Release files for Py-redis-ratelimit 0.1.4

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

Source distribution (sdist)

Source distribution for Py-redis-ratelimit 0.1.4
File Size Uploaded
Py-redis-ratelimit-0.1.4.tar.gz 4.3 kB Details

Release files / Py-redis-ratelimit-0.1.4.tar.gz

Download URL Py-redis-ratelimit-0.1.4.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b2be224f0842aeec12f2884f28ea643a3492868734ddbee9f3f457848d412be7
BLAKE2b-256 checksum
How to use checksums
a3231351cb5bf0f1c0298fb49ffc524de8f9aec19d079b26fa42e62a9778521a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.0

Release history Release notifications | RSS feed

This release

0.1.4 This release

1 release file

0.1.2

1 release file

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