base
Rate Limit Protocols for Synchronous and Asynchronous Context Managers
AsyncRateLimit
Bases: Protocol
Asynchronous Rate Limit Protocol
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bucket_config
|
BucketConfig
|
Configuration for the rate limit |
required |
max_concurrent
|
int | None
|
Maximum number of concurrent requests allowed to acquire capacity |
None
|
Source code in limitor/base.py
__aenter__()
async
Enter the context manager, acquiring resources if necessary
This method should return an instance of AsyncRateLimit
Returns:
| Type | Description |
|---|---|
AsyncRateLimit
|
An instance of the rate limit context manager |
Source code in limitor/base.py
__aexit__(exc_type, exc_val, exc_tb)
async
Exit the context manager, releasing any resources if necessary
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exc_type
|
type[BaseException]
|
The type of the exception raised, if any |
required |
exc_val
|
BaseException
|
The value of the exception raised, if any |
required |
exc_tb
|
TracebackType
|
The traceback object, if any |
required |
Source code in limitor/base.py
acquire(amount=1, timeout=None)
async
Acquire an item from the rate limit. This method should block until a token is available
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amount
|
float
|
The amount of capacity to acquire, defaults to 1 |
1
|
timeout
|
float | None
|
Optional timeout in seconds for the acquire operation |
None
|
Source code in limitor/base.py
HasCapacity
Bases: Protocol
Protocol for objects that have a capacity attribute
Source code in limitor/base.py
capacity
instance-attribute
Maximum number of items the bucket can hold i.e. number of requests that can be processed at once
SyncRateLimit
Bases: Protocol
Synchronous Rate Limit Protocol
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bucket_config
|
BucketConfig
|
Configuration for the rate limit |
required |
Source code in limitor/base.py
__enter__()
Enter the context manager, acquiring resources if necessary
This method should return an instance of SyncRateLimit
Returns:
| Type | Description |
|---|---|
SyncRateLimit
|
An instance of the rate limit context manager |
Source code in limitor/base.py
__exit__(exc_type, exc_val, exc_tb)
Exit the context manager, releasing any resources if necessary
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exc_type
|
type[BaseException]
|
The type of the exception raised, if any |
required |
exc_val
|
BaseException
|
The value of the exception raised, if any |
required |
exc_tb
|
TracebackType
|
The traceback object, if any |
required |
Source code in limitor/base.py
acquire(amount=1)
Acquire an item from the rate limit. This method should block until a token is available
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amount
|
float
|
The amount of capacity to acquire, defaults to 1 |
1
|