A robust and versatile throttling implementation relying on the token bucket algorithm.
Project description
throttle
========
The throttle library provides a robust and versatile throttling mechanism for Python.
It can be used in multiple environments, from a single thread to a distributed
server cluster.
It supports Python versions 2.6 to 3.3.
Usage
-----
In order to perform throttling tasks, simply use the :meth:`~throttle.throttle`
function:
.. code-block:: python
import throttle
def some_fun(uid):
if not throttle.check(key=uid, rate=30, size=10):
raise ThrottleError()
# Do the job
Algorithm
---------
throttle uses the "token bucket" algorithm: for each key, a virtual bucket
exists.
Whenever a new request gets in, the algorithm performs the following actions:
- Test if adding the request's cost to the bucket would exceed its capacity;
in that case, return False
- Otherwise, add the request's cost to the bucket, and return True
Simultaneously, the bucket's current value is decremented at the chosen rate.
This allows for temporary bursts and average computations.
Installing
----------
From pip (https://pypi.python.org/pypi/throttle):
.. code-block:: sh
$ pip install throttle
From Github:
.. code-block:: sh
$ git clone git://github.com/rbarrois/throttle.git
========
The throttle library provides a robust and versatile throttling mechanism for Python.
It can be used in multiple environments, from a single thread to a distributed
server cluster.
It supports Python versions 2.6 to 3.3.
Usage
-----
In order to perform throttling tasks, simply use the :meth:`~throttle.throttle`
function:
.. code-block:: python
import throttle
def some_fun(uid):
if not throttle.check(key=uid, rate=30, size=10):
raise ThrottleError()
# Do the job
Algorithm
---------
throttle uses the "token bucket" algorithm: for each key, a virtual bucket
exists.
Whenever a new request gets in, the algorithm performs the following actions:
- Test if adding the request's cost to the bucket would exceed its capacity;
in that case, return False
- Otherwise, add the request's cost to the bucket, and return True
Simultaneously, the bucket's current value is decremented at the chosen rate.
This allows for temporary bursts and average computations.
Installing
----------
From pip (https://pypi.python.org/pypi/throttle):
.. code-block:: sh
$ pip install throttle
From Github:
.. code-block:: sh
$ git clone git://github.com/rbarrois/throttle.git
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
File details
Details for the file throttle-memcache-0.1.5.tar.gz.
File metadata
- Download URL: throttle-memcache-0.1.5.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48018dd390b0fe0d9b08cc0025249e6e8e9eec1c61929052938f1ce8a5994c41
|
|
| MD5 |
a462b5ece20cfefacc1ae03b1f820003
|
|
| BLAKE2b-256 |
cc925d28d90a8e0ed03a09ff125bacc382afc32c1e5786b1b0d4cd76cec083c3
|