drygdryg / limits

Rate limiting using various strategies and storage backends such as redis & memcached

Home Page:https://limits.readthedocs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

limits

docs ci codecov pypi pypi-versions license

limits is a python library to perform rate limiting with commonly used storage backends (Redis, Memcached, MongoDB & Etcd).


Sponsored by Zuplo - fully-managed, programmable API Management platform. Add rate limiting and more to your public API in minutes, try it at zuplo.com


Supported Strategies

Fixed Window

This strategy resets at a fixed interval (start of minute, hour, day etc). For example, given a rate limit of 10/minute the strategy will:

  • Allow 10 requests between 00:01:00 and 00:02:00
  • Allow 10 requests at 00:00:59 and 10 more requests at 00:01:00
Fixed Window (Elastic)

Identical to Fixed window, except every breach of rate limit results in an extension to the time out. For example a rate limit of 1/minute hit twice within a minute will result in a lock-out for two minutes.

Moving Window

Sliding window strategy enforces a rate limit of N/(m time units) on the last m time units at the second granularity.

For example, with a rate limit of 10/minute:

  • Allow 9 requests that arrive at 00:00:59
  • Allow another request that arrives at 00:01:00
  • Reject the request that arrives at 00:01:01

Storage backends

Dive right in

Initialize the storage backend

Initialize a rate limiter with the Moving Window Strategy

Initialize a rate limit

Initialize a rate limit explicitly

Test the limits

Check specific limits without hitting them

About

Rate limiting using various strategies and storage backends such as redis & memcached

https://limits.readthedocs.org

License:MIT License


Languages

Language:Python 98.9%Language:Shell 0.6%Language:Lua 0.4%Language:Makefile 0.1%