DESCRIPTION.rst 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. Ratelim
  2. =======
  3. 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.
  4. Features
  5. --------
  6. - Works in Py2 and Py3.
  7. - Greedy and patient rate limiting.
  8. - Preserves function signature.
  9. Installation
  10. ------------
  11. .. code-block:: bash
  12. $ pip install ratelim
  13. Usage
  14. -----
  15. Say you want to call a function at most for ``n_calls`` during a ``n_seconds`` time interval.
  16. .. code-block:: python
  17. # 10 times in 5 seconds
  18. @ratelim.greedy(10, 5)
  19. def hello():
  20. print("hello")
  21. The ``greedy`` rate limiter calls does not delay any function call until it's really necessary.
  22. In some scenarios, for example when crawling data from an API, you want to maximize the number
  23. of calls you make and you want to avoid sending them in short sequence. To this aim, we can
  24. use the ``patient`` rate limiter. It distributes calls evenly between each other.
  25. .. code-block:: python
  26. # 10 times in 5 seconds
  27. # Gets called at most every 0.5 seconds
  28. @ratelim.patient(10, 5)
  29. def hello():
  30. print("hello")
  31. LICENSE
  32. -------
  33. MIT.