limitor
Main module for rate limiting functionality.
async_rate_limit(_func=None, *, capacity=10, seconds=1, max_concurrent=None, bucket_cls=AsyncLeakyBucket)
Decorator to apply an asynchronous leaky bucket rate limit to a function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_func
|
Callable[P, Awaitable[R]] | None
|
Function to apply the rate limit to the function |
None
|
capacity
|
float
|
Maximum number of requests allowed in the bucket, defaults to 10 |
10
|
seconds
|
float
|
Time period in seconds for the bucket to refill, defaults to 1 |
1
|
max_concurrent
|
int | None
|
Maximum number of concurrent requests allowed, defaults to None (no limit) |
None
|
bucket_cls
|
type[AsyncRateLimit]
|
Bucket class, defaults to AsyncLeakyBucket |
AsyncLeakyBucket
|
Returns:
| Type | Description |
|---|---|
Callable[P, Awaitable[R]] | Callable[[Callable[P, Awaitable[R]]], Callable[P, Awaitable[R]]]
|
A decorator that applies the rate limit to the function |
Source code in limitor/__init__.py
rate_limit(_func=None, *, capacity=10, seconds=1, bucket_cls=SyncLeakyBucket)
Decorator to apply a synchronous leaky bucket rate limit to a function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_func
|
Callable[P, R] | None
|
Function to apply the rate limit to the function |
None
|
capacity
|
float
|
Maximum number of requests allowed in the bucket, defaults to 10 |
10
|
seconds
|
float
|
Time period in seconds for the bucket to refill, defaults to 1 |
1
|
bucket_cls
|
type[SyncRateLimit]
|
Bucket class, defaults to SyncLeakyBucket |
SyncLeakyBucket
|
Returns:
| Type | Description |
|---|---|
Callable[P, R] | Callable[[Callable[P, R]], Callable[P, R]]
|
A decorator that applies the rate limit to the function |