A client throttle tool based on redis.
Project description
Client Throttler
Overview
A proactive rate-limiting tool utilizing Redis.
Users can actively limit the call frequency of functions or methods, and calls that would cause exceeding the limit will be delayed until they can be executed.
Getting started
Installation
$ pip install client_throttler
Usage
-
[Optional] Configure a default Redis client for all Throttler rate limiters.
from redis.client import Redis from client_throttler import setup, ThrottlerConfig setup(ThrottlerConfig(redis_client=Redis(host="localhost", port=1234, db=1)))
-
Simply add a decorator to the function or method that needs to have its calls limited.
from redis.client import Redis from client_throttler import throttler, ThrottlerConfig, Throttler redis_client = Redis(host="localhost", port=1234, db=2) # use default config @throttler() def func_a(*args, **kwargs): return args, kwargs # use default config, and change custom config @throttler(ThrottlerConfig(rate="1/2s")) def func_b(*args, **kwargs): return args, kwargs # use default config, and change redis client and some custom config @throttler(ThrottlerConfig(rate="1/2s", redis_client=redis_client)) def func_c(*args, **kwargs): return args, kwargs # change a callable into throttled callable def func_d(*args, **kwargs): return args, kwargs func = Throttler(ThrottlerConfig(func=func_d)) func(*args, **kwargs)
License
Based on the MIT protocol. Please refer to LICENSE
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file client_throttler-1.0.1.tar.gz
.
File metadata
- Download URL: client_throttler-1.0.1.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42597ace195683d224e0ab05fc6d449ffa4be0077356648f75b5840ed1f8f5a8 |
|
MD5 | 5a33529d7c24927595b3c657c204716a |
|
BLAKE2b-256 | 014740940b1344f77a13e1d61ec76056f18ad6a8dcfa3fdcef8ca9740fc04c1b |
File details
Details for the file client_throttler-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: client_throttler-1.0.1-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17949e71f9c4293b6635dae134e3930ad0e505bf8c02503f1963c6402b3f6459 |
|
MD5 | a705439bdd46199a77f4ee4214ea72cd |
|
BLAKE2b-256 | b3024caab3769899ca7ad7e1e0ddd6888348feb4af6e8bebfea4d969f7b76876 |