http
Class for interacting with paginated APIs over HTTP.
HTTPClient(base_url='', per_page=100, timeout=5.0, verify=True, *, headers=None, client=None, verbose=True, batch_size=10, n_workers=2, retries=3, on_errors='warn')
¶
HTTP client for interacting with paginated API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base_url |
str
|
The base URL of the API. |
''
|
per_page |
int
|
Default number of entries per page, default 100 |
100
|
timeout |
float
|
Maximum timeout for requests in seconds, default 5.0 |
5.0
|
verify |
bool or str
|
Verify SSL credentials, default True Also accepts a path string to an SSL certificate file. |
True
|
headers |
dict[str, str]
|
Collection of headers to send with each request, default None |
None
|
client |
AsyncClient
|
Authenticated |
None
|
verbose |
bool
|
Set to False to disable progress bar, default True |
True
|
batch_size |
int
|
Size of batches to make requests with, default 10 |
10
|
n_workers |
int
|
Number of workers to make requests, default 2 |
2
|
retries |
int
|
Number of times to retry a request, default 3 |
3
|
on_errors |
Literal['warn', 'raise']
|
Warn about failed requests or raise immediately on failure, default |
'warn'
|
Source code in bavapi/http.py
aclose()
async
¶
get(endpoint, query)
async
¶
Perform GET request on the given endpoint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
endpoint |
str
|
Path to endpoint. |
required |
query |
Query
|
Request parameters. |
required |
Returns:
Type | Description |
---|---|
Response
|
Requested response object. |
Raises:
Type | Description |
---|---|
APIError
|
If request fails. |
Source code in bavapi/http.py
get_pages(endpoint, query, n_pages)
async
¶
Perform GET requests for a given number of pages on an endpoint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
endpoint |
str
|
Path to endpoint. |
required |
query |
Query
|
Request parameters. |
required |
n_pages |
int
|
Number of pages to request. |
required |
Returns:
Type | Description |
---|---|
list[Response]
|
List of response objects. |
Source code in bavapi/http.py
query(endpoint, query)
async
¶
Perform a paginated GET request on the given endpoint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
endpoint |
str
|
Path to endpoint. |
required |
query |
Query
|
Request parameters. |
required |
Returns:
Type | Description |
---|---|
Iterator[JSONDict]
|
An iterator of JSONDict objects. |
Raises:
Type | Description |
---|---|
APIError
|
If any request fails. |
DataNotFoundError
|
If response data is empty. |
RateLimitExceededError
|
If response would exceed the rate limit. |