Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/theruziev/aiorate_limiter
A simple asyncio ready python implementation of a general purpose rate limiter based on Token Bucket algorithm
https://github.com/theruziev/aiorate_limiter
asyncio python36 python37 rate-limiter tokenbucket
Last synced: about 1 month ago
JSON representation
A simple asyncio ready python implementation of a general purpose rate limiter based on Token Bucket algorithm
- Host: GitHub
- URL: https://github.com/theruziev/aiorate_limiter
- Owner: theruziev
- License: mit
- Created: 2019-08-23T11:02:39.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-06-02T12:57:50.000Z (over 1 year ago)
- Last Synced: 2023-06-02T14:15:30.274Z (over 1 year ago)
- Topics: asyncio, python36, python37, rate-limiter, tokenbucket
- Language: Python
- Homepage:
- Size: 135 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 9
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
.. image:: https://img.shields.io/travis/com/theruziev/aiorate_limiter.svg?style=flat-square
:target: https://travis-ci.com/theruziev/aiorate_limiter
.. image:: https://img.shields.io/codecov/c/github/theruziev/aiorate_limiter.svg?style=flat-square
:target: https://codecov.io/gh/theruziev/aiorate_limiterAioRate Limiter
===============A simple **asyncio**-ready Python implementation of a general purpose rate limiter based on
`Token Bucket algorithm `_.Supported storage
-----------------* Memory
* Redis (`aioredis `_)⚡ Quickstart
-------------RateLimiter is really easy to use.
Basic Example:
~~~~~~~~~~~~~~.. code-block:: python
# 5 req/sec
opts = RateLimiterOpts(points=5, duration=1000)
limiter = MemoryRateLimiter(opts)
# initialize limiter
await limiter.init()
# Consume
result = limiter.consume("request_1", 1) # Consume for a request_1 1 point
# Check is allowed
if result.is_allowed:
# Happy!!! 1 point consumed
else:
# Be a strong, points is ended. Try again later.RateLimiterOpts
~~~~~~~~~~~~~~~Options class for a configure rate limiter
**Params:**
* **points** - Maximum number of points can be consumed over duration
* **duration** - Number of milliseconds before consumed points are reset
* **key_prefix** - If you need to create several limiters for different purpose.RateLimiterResult
~~~~~~~~~~~~~~~~~An object which returned when consume points
**Params:**
* **remaining_points** - Number of remaining points in current duration
* **ms_before_next** - Number of milliseconds before next action can be done
* **consumed_points** - Number of consumed points in current duration
* **is_allowed** - Result of consume, true if allow otherwise falseDeveloping
-------------To install development dependencies:
.. code-block:: bash
make install
Lint:
.. code-block:: bash
make lint
Formatting code:
.. code-block:: bash
make format
Test:
.. code-block:: bash
make test
# or run tox
tox