Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rbarrois/throttle
UNMAINTAINED - A simple Python throttling lib relying on the token bucket algorithm
https://github.com/rbarrois/throttle
Last synced: 3 months ago
JSON representation
UNMAINTAINED - A simple Python throttling lib relying on the token bucket algorithm
- Host: GitHub
- URL: https://github.com/rbarrois/throttle
- Owner: rbarrois
- License: bsd-2-clause
- Archived: true
- Created: 2014-01-07T13:36:48.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2017-01-27T16:10:10.000Z (about 8 years ago)
- Last Synced: 2024-11-04T21:48:21.050Z (4 months ago)
- Language: Python
- Homepage:
- Size: 105 KB
- Stars: 38
- Watchers: 2
- Forks: 9
- Open Issues: 7
-
Metadata Files:
- Readme: README
- Changelog: ChangeLog
- License: LICENSE
Awesome Lists containing this project
- starred-awesome - throttle - UNMAINTAINED - A simple Python throttling lib relying on the token bucket algorithm (Python)
README
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 jobAlgorithm
---------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 TrueSimultaneously, 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