All Projects → alisaifee → limits

alisaifee / limits

Licence: MIT license
Rate limiting using various strategies and storage backends such as redis & memcached

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to limits

Dalli Rate limiter
Arbitrary Memcached-backed rate limiting for Ruby
Stars: ✭ 38 (-78.65%)
Mutual labels:  memcached, rate-limiting
cache-all
Fast, efficient cache engines for both express routes & native nodeJs (redis, in-memory & file cache)
Stars: ✭ 22 (-87.64%)
Mutual labels:  memcached
sparql-proxy
SPARQL-proxy: provides cache, job control, and logging for any SPARQL endpoint
Stars: ✭ 26 (-85.39%)
Mutual labels:  memcached
session
Aplus Framework Session Library
Stars: ✭ 170 (-4.49%)
Mutual labels:  memcached
libmemcached
Resurrection of libmemcached
Stars: ✭ 30 (-83.15%)
Mutual labels:  memcached
dxram
A distributed in-memory key-value storage for billions of small objects.
Stars: ✭ 25 (-85.96%)
Mutual labels:  memcached
memcached-spring-boot
Library that provides support for auto-configuration of Memcached cache in a Spring Boot application.
Stars: ✭ 68 (-61.8%)
Mutual labels:  memcached
webuntis
A API library that makes it easy to access the Webuntis JSON RPC 2.0 API
Stars: ✭ 22 (-87.64%)
Mutual labels:  memcached
db wlan manager
Monitors your Wifi to keep you logged in and resets your Wifi, if your data is drained
Stars: ✭ 23 (-87.08%)
Mutual labels:  rate-limiting
django-test-addons
Testing support for different database system like Mongo, Redis, Neo4j, Memcache, Django Rest Framework for django
Stars: ✭ 20 (-88.76%)
Mutual labels:  memcached
hibernate-l2-memcached
Hibernate second level cache implementation over memcached
Stars: ✭ 34 (-80.9%)
Mutual labels:  memcached
resque-waiting-room
Resque plugin that throttles your jobs
Stars: ✭ 34 (-80.9%)
Mutual labels:  rate-limiting
phalcon-throttler
Phalcon Throttler is a Rate Limiter for the PHP Phalcon Framework.
Stars: ✭ 19 (-89.33%)
Mutual labels:  rate-limiting
EnumerableAsyncProcessor
Process Multiple Asynchronous Tasks in Various Ways - One at a time / Batched / Rate limited / Concurrently
Stars: ✭ 84 (-52.81%)
Mutual labels:  rate-limiting
rush
rush.readthedocs.io/en/latest/
Stars: ✭ 42 (-76.4%)
Mutual labels:  rate-limiting
docker-lemp
A single container LEMP complete fullstack with latest release of PHP7.4.33, 8.0.26 & 8.1.13/8.2RC and MySQL, nginx, PostgreSQL, phalcon, swoole, mailcatcher, beanstalkd, elasticsearch, memcached, redis, adminer and all you ever need; on top alpine3.15
Stars: ✭ 106 (-40.45%)
Mutual labels:  memcached
aiomcache
Minimal asyncio memcached client
Stars: ✭ 129 (-27.53%)
Mutual labels:  memcached
fortune-commons
Fortune Commons is an project focused on all aspects of reusable Java components.
Stars: ✭ 17 (-90.45%)
Mutual labels:  memcached
kdk memcached object cache
Object cache driver for Memcached in WordPress (based on Memcached Redux)
Stars: ✭ 20 (-88.76%)
Mutual labels:  memcached
High-Traffic-wordpress-server-configuration
High Traffic WordPress server configuration Nginx (updated) PHP 7.4 PHP-fpm Mariadb (updated) Wordpress (updated) Cloudflare Full SSL
Stars: ✭ 31 (-82.58%)
Mutual labels:  memcached

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).

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

from limits import storage
memory_storage = storage.MemoryStorage()
# or memcached
memcached_storage = storage.MemcachedStorage("memcached://localhost:11211")
# or redis
redis_storage = storage.RedisStorage("redis://localhost:6379")
# or leave it to fate
some_storage = storage.storage.from_string(fate)

Initialize a rate limiter with the Moving Window Strategy

from limits import strategies
moving_window = strategies.MovingWindowRateLimiter(memory_storage)

Initialize a rate limit

from limits import parse
one_per_minute = parse("1/minute")

Initialize a rate limit explicitly

from limits import RateLimitItemPerSecond
one_per_second = RateLimitItemPerSecond(1, 1)

Test the limits

assert True == moving_window.hit(one_per_minute, "test_namespace", "foo")
assert False == moving_window.hit(one_per_minute, "test_namespace", "foo")
assert True == moving_window.hit(one_per_minute, "test_namespace", "bar")

assert True == moving_window.hit(one_per_second, "test_namespace", "foo")
assert False == moving_window.hit(one_per_second, "test_namespace", "foo")
time.sleep(1)
assert True == moving_window.hit(one_per_second, "test_namespace", "foo")

Check specific limits without hitting them

assert True == moving_window.hit(one_per_second, "test_namespace", "foo")
while not moving_window.test(one_per_second, "test_namespace", "foo"):
    time.sleep(0.01)
assert True == moving_window.hit(one_per_second, "test_namespace", "foo")

Links

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].