Skip to main content

A client throttle tool based on redis.

Project description

Client Throttler

license Release Version PRs Welcome Unittest codecov

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

  1. [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)))
    
  2. 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


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.2.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

client_throttler-1.0.2-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file client_throttler-1.0.2.tar.gz.

File metadata

  • Download URL: client_throttler-1.0.2.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for client_throttler-1.0.2.tar.gz
Algorithm Hash digest
SHA256 9ded3f0af588ca07706bc559cd0ea9a165661a03ead5a8ad4ba9cfd6314b271e
MD5 490b5d347b6c11c7156a3a586ef1d0e2
BLAKE2b-256 dc39d367581c5df26a89a87f4b9a1d4ae54901c58c19425595a6cd424f17501e

See more details on using hashes here.

File details

Details for the file client_throttler-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for client_throttler-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ecf015276c62aa2333450cd4e6fbb1474a092e36a90a9f970df8df5f36d7ae82
MD5 adc61fa92875a3128b06766cec732bd9
BLAKE2b-256 d1c045f89b0a956a3d8755a7dd0c94328398fc4da811cc3893a016e70e1a18b9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page