Factory
RateLimitedAsyncHttpClient
An asynchronous HTTP client with rate limiting.
This class allows you to make HTTP requests with rate limiting to prevent exceeding a maximum number of requests within a specified time period.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url |
str
|
The base URL for the HTTP requests. |
required |
max_calls |
int
|
The maximum number of allowed calls within the specified period. |
required |
period |
int
|
The time period (in seconds) during which the maximum calls are allowed. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
base_url |
str
|
The base URL for the HTTP requests. |
max_calls |
int
|
The maximum number of allowed calls within the specified period. |
period |
int
|
The time period (in seconds) during which the maximum calls are allowed. |
semaphore |
Semaphore
|
An asyncio semaphore used for rate limiting. |
Source code in libs/python/shared/py-request/pyrequest/factory.py
__init__(base_url, max_calls, period)
Initialize the RateLimitedAsyncHttpClient with the specified parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url |
str
|
The base URL for the HTTP requests. |
required |
max_calls |
int
|
The maximum number of allowed calls within the specified period. |
required |
period |
int
|
The time period (in seconds) during which the maximum calls are allowed. |
required |
Source code in libs/python/shared/py-request/pyrequest/factory.py
make_request(method, endpoint, data=None, params=None)
async
Make an asynchronous HTTP request with rate limiting.
This method sends an HTTP request using the specified method, endpoint, data, and parameters. Rate limiting is enforced to prevent exceeding the maximum number of calls within the specified period.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method |
str
|
The HTTP request method (e.g., 'GET', 'POST'). |
required |
endpoint |
str
|
The endpoint to request, relative to the base URL. |
required |
data |
dict
|
A dictionary of data to send in the request body (as JSON). |
None
|
params |
dict
|
A dictionary of query parameters to include in the request. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dict[str, any]
|
A dictionary representing the JSON response from the HTTP request. |
Raises:
| Type | Description |
|---|---|
HTTPStatusError
|
If the HTTP request results in an error response. |