Skip to main content

A distributed rate limiting library for python using leaky bucket algorithm and Redis

Project description

# Prerequisites
This library makes use of Redis and needs it as a prerequisite. Redis sentinel is also supported.
Make sure that Redis server is running before using this library

# Example
For this example, let's assume that redis hostname is 'localhost' and port number is 6379
Suppose you want to limit the number of api calls to be 1000 per minute. It can be done by the following steps.

1.) Import the library:-

from pylimit import PyLimit

2.) Initialize the library

PyLimit.init(redis_host="localhost", redis_port=6379)

3.) Create a rate limit namespace

limit = PyLimit()
limit.create('api_count', # namespace
60, # rate limit period in seconds
100) # no of attempts in the time period


4.) Record ant attempt and check if it is allowed or not
``
is_allowed = limit.attempt('api_count') # will return true if number of attempts
# are less than or equal to 1000 in last 1 minute,
# false otherwise
``

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

pylimit-0.1.1.tar.gz (2.5 kB view hashes)

Uploaded Source

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