An active current limiting algorithm based on redis atomic implementation.
Project description
Client Throttler
Overview
A distributed proactive rate limiting algorithm based on Redis.
Users can proactively limit the invocation frequency of methods or functions.
Calls that exceed the limit will not be discarded, but will instead be queued and retried in the next cycle based on the calculated delay time.
Getting started
Installation
$ pip install client_throttler
Usage
# -*- coding: utf-8 -*-
import asyncio
from redis.client import Redis
from client_throttler.throttler import throttler
redis_client = Redis(host="localhost", port=1234, db=1)
@throttler(rate="1/2s", redis_client=redis_client)
async def funcA(*args, **kwargs):
return args, kwargs
class TestAPI:
api = "test_api"
@throttler(rate="1/2s", redis_client=redis_client)
async def funcB(self):
return self.api
def funcD(self):
return self.api
def funcC(*args, **kwargs):
return args, kwargs
async def main():
result_a = await funcA(1, 2, 3, name=1, age=2)
print("A:", result_a)
result_b = await TestAPI().funcB()
print("B:", result_b)
result_c = funcC(1, 2, 3, name=1, age=2)
print("C:", result_c)
result_d = TestAPI().funcD()
print("D:", result_d)
if __name__ == "__main__":
asyncio.run(main())
"""
A: ((1, 2, 3), {'name': 1, 'age': 2})
B: test_api
C: ((1, 2, 3), {'name': 1, 'age': 2})
D: test_api
"""
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
client_throttler-1.0.0.tar.gz
(5.8 kB
view hashes)
Built Distribution
Close
Hashes for client_throttler-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a3a87676d81dc24c4d5924c4c717b66571c0a16b54ce9920937b0ed62876cae |
|
MD5 | b9f9f7ab751595bccc18b5dfb075b528 |
|
BLAKE2b-256 | 9b0c87671c56d7e6ed6111acb9bf7982b6475cd8b46354c2bac4c3149cfee774 |