Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/themiurgo/ratelim
Makes it easy to respect rate limits.
https://github.com/themiurgo/ratelim
Last synced: 3 months ago
JSON representation
Makes it easy to respect rate limits.
- Host: GitHub
- URL: https://github.com/themiurgo/ratelim
- Owner: themiurgo
- License: mit
- Created: 2014-12-21T07:05:26.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-01-10T09:54:37.000Z (about 8 years ago)
- Last Synced: 2024-09-20T00:21:59.891Z (4 months ago)
- Language: Python
- Size: 9.77 KB
- Stars: 94
- Watchers: 4
- Forks: 4
- Open Issues: 4
-
Metadata Files:
- Readme: README.rst
- Changelog: HISTORY.rst
- License: LICENSE
Awesome Lists containing this project
- starred-awesome - ratelim - Makes it easy to respect rate limits. (Python)
README
Ratelim
=======Ratelim is a simple Python library that limits the number of times a function can be called during a time interval. It is particularly useful when using online APIs, which commonly enforce rate limits.
Features
--------- Works in Py2 and Py3.
- Greedy and patient rate limiting.
- Preserves function signature.Installation
------------.. code-block:: bash
$ pip install ratelim
Usage
-----Say you want to call a function at most for ``n_calls`` during a ``n_seconds`` time interval.
.. code-block:: python
# 10 times in 5 seconds
@ratelim.greedy(10, 5)
def hello():
print("hello")The ``greedy`` rate limiter calls does not delay any function call until it's really necessary.
In some scenarios, for example when crawling data from an API, you want to maximize the number
of calls you make and you want to avoid sending them in short sequence. To this aim, we can
use the ``patient`` rate limiter. It distributes calls evenly between each other... code-block:: python
# 10 times in 5 seconds
# Gets called at most every 0.5 seconds
@ratelim.patient(10, 5)
def hello():
print("hello")Contribute
----------You are more than welcome to contribuite to this project. You can open a new issue to report a bug or a wanted feature. You can also contribute directly with code, by sending a pull request.
LICENSE
-------MIT.