Reference for hub_sdk/base/paginated_list.py
Note
This file is available at https://github.com/ultralytics/hub-sdk/blob/main/hub_sdk/base/paginated_list.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
hub_sdk.base.paginated_list.PaginatedList
Bases: APIClient
Handles pagination for list endpoints on the API while managing retrieval, navigation, and updating of data.
This class extends APIClient to provide pagination functionality for API endpoints that return large datasets. It manages page navigation, data retrieval, and state tracking across paginated results.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
Descriptive name for the paginated resource. |
page_size |
int
|
Number of items to display per page. |
public |
bool
|
Filter for public resources if specified. |
pages |
List
|
List tracking page identifiers for navigation. |
current_page |
int
|
Index of the currently displayed page. |
total_pages |
int
|
Total number of available pages. |
results |
dict
|
Current page results from the API. |
Methods:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base_endpoint
|
str
|
The base API endpoint for the paginated resource. |
required |
name
|
str
|
A descriptive name for the paginated resource. |
required |
page_size
|
int
|
The number of items per page. |
None
|
public
|
bool
|
Filter for public resources if specified. |
None
|
headers
|
dict
|
Additional headers to include in API requests. |
None
|
Source code in hub_sdk/base/paginated_list.py
__update_data
Update the internal data with the response from the API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resp
|
Response
|
API response data containing pagination information and results. |
required |
Source code in hub_sdk/base/paginated_list.py
list
Retrieve a list of items from the API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
page_size
|
int
|
The number of items per page. |
10
|
last_record
|
str
|
ID of the last record from the previous page for cursor-based pagination. |
None
|
query
|
dict
|
Additional query parameters for the API request. |
None
|
Returns:
Type | Description |
---|---|
Optional[Response]
|
Response object from the list request, or None if the request fails. |
Source code in hub_sdk/base/paginated_list.py
next
Move to the next page of results if available.
Source code in hub_sdk/base/paginated_list.py
previous
Move to the previous page of results if available.