Async Support¶
The namespace limits.aio mirrors limits.storage and limits.strategies
with async variants.
The following async storage backends are implemented:
In-Memory
Redis (via coredis or redis-py. Refer to
limits.aio.storage.RedisStorage.implementationfor details on selecting the dependency)Memcached (via memcachio)
MongoDB (via motor)
Quick start¶
This example demonstrates the subtle differences in the limits.aio namespace:
from limits import parse
from limits.storage import storage_from_string
from limits.aio.strategies import MovingWindowRateLimiter
redis = storage_from_string("async+redis://localhost:6379")
moving_window = MovingWindowRateLimiter(redis)
one_per_minute = parse("1/minute")
async def hit():
return await moving_window.hit(one_per_minute, "test_namespace", "foo")
Refer to Async Storage for more implementation details of the async storage backends, and Async Strategies for the async rate limit strategies API.