Pagination | spectrumx.ops.pagination
spectrumx.ops.pagination
Pagination for SDS constructs.
Classes:
| Name | Description |
|---|---|
Paginator |
Manages the state for paginating through files in SDS. |
Functions:
| Name | Description |
|---|---|
main |
Usage example for paginator. |
Classes
Paginator
Paginator(
*,
Entry: type[SDSModel],
gateway: GatewayClient,
list_method: Callable[..., bytes],
list_kwargs: dict[str, Any],
dry_run: bool = False,
page_size: int = 30,
start_page: int = 1,
total_matches: int | None = None,
verbose: bool = False,
)
Bases: Generic[T]
flowchart TD
spectrumx.ops.pagination.Paginator[Paginator]
click spectrumx.ops.pagination.Paginator href "" "spectrumx.ops.pagination.Paginator"
Manages the state for paginating through files in SDS.
A Paginator instance may be iterated over to fetch and return parsed entries automatically. Note that network calls will happen in the background and fetching requests happen once per page. Iterating it also consumes the generator, so any yielded content should be stored if needed in the future.
Usage example
# For file listings
file_paginator = Paginator[File](
Entry=File,
gateway=gateway,
list_method=gateway.list_files,
list_kwargs={"sds_path": "/path/to/files"},
dry_run=False,
verbose=True,
)
# For dataset files
dataset_paginator = Paginator[File](
Entry=File,
gateway=gateway,
list_method=gateway.get_dataset_files,
list_kwargs={"dataset_uuid": "123e4567-e89b-12d3-a456-426614174000"},
dry_run=False,
verbose=True,
)
print(f"Total files matched: {len(file_paginator)}")
# len() will fetch the first page
for my_file in file_paginator:
print(f"Processing file: {my_file.name}")
process_file(my_file)
# new pages are fetched automatically
for _my_file in file_paginator:
msg = "This will not run, as the paginator was consumed."
raise AssertionError(msg)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Entry
|
type[SDSModel]
|
The SDSModel subclass to use when parsing the entries. |
required |
gateway
|
GatewayClient
|
The gateway client to use for fetching pages. |
required |
list_method
|
Callable[..., bytes]
|
The method to call for fetching pages (e.g., gateway.list_files). |
required |
list_kwargs
|
dict[str, Any]
|
Keyword arguments to pass to the list_method. |
required |
dry_run
|
bool
|
If True, will generate synthetic pages instead of fetching. |
False
|
page_size
|
int
|
The number of entries to fetch per page. |
30
|
start_page
|
int
|
The page number to start fetching from. |
1
|
total_matches
|
int | None
|
The total number of entries across all pages. |
None
|
verbose
|
bool
|
If True, will log more information about the pagination. |
False
|
- API Reference
-
API Reference
SDS Client | spectrumx.client.Client
Client Functionsdownload
Source code in spectrumx/ops/pagination.py
Functions
main
Usage example for paginator.