ds_protocol_http_py_lib.dataset.pagination.strategies.base

File: base.py Region: ds_protocol_http_py_lib/dataset/pagination/strategies/base

Base ABC for registered pagination strategies (page-variation hooks only).

Concrete strategies (offset, page-number, cursor, …) inherit this. The HTTP drain loop lives on Paginate, which uses a strategy — strategies do not own run.

Attributes

ConfigT

Classes

PageState

Strategy-owned traversal state for one paginated read.

PaginationStrategyHandler

Page-variation contract parameterized by the strategy settings nest.

Functions

is_short_or_empty_page(→ bool)

True when the page is empty or shorter than the requested page size.

Module Contents

ds_protocol_http_py_lib.dataset.pagination.strategies.base.ConfigT
class ds_protocol_http_py_lib.dataset.pagination.strategies.base.PageState[source]

Strategy-owned traversal state for one paginated read.

values: dict[str, Any]

Opaque strategy values (offset, page, cursor, …).

page_index: int = 0

Zero-based count of pages fetched so far.

class ds_protocol_http_py_lib.dataset.pagination.strategies.base.PaginationStrategyHandler[source]

Bases: abc.ABC, Generic[ConfigT]

Page-variation contract parameterized by the strategy settings nest.

Each concrete strategy binds ConfigT to its nest type (e.g. CursorPaginationSettings) so hook signatures stay precise.

abstractmethod initial_state(cfg: ConfigT, checkpoint_slice: dict[str, Any] | None) → PageState[source]

Build the starting page state, optionally restoring from checkpoint.

abstractmethod inject(request: ds_protocol_http_py_lib.utils.http.request.RequestSnapshot, state: PageState, cfg: ConfigT) → ds_protocol_http_py_lib.utils.http.request.RequestSnapshot[source]

Return a request snapshot with pagination values applied.

abstractmethod advance(*, body: Any, headers: Any, items: list[Any], state: PageState, cfg: ConfigT) → PageState[source]

Advance state after a successful page response.

abstractmethod should_stop(*, body: Any, headers: Any, items: list[Any], state: PageState, cfg: ConfigT) → bool[source]

Return True when traversal should terminate after this page.

abstractmethod to_checkpoint(state: PageState) → dict[str, Any][source]

Serialize traversal state into the checkpoint pagination slice.

abstractmethod from_checkpoint(data: dict[str, Any]) → PageState[source]

Restore traversal state from a checkpoint pagination slice.

ds_protocol_http_py_lib.dataset.pagination.strategies.base.is_short_or_empty_page(items: list[Any], page_size: int) → bool[source]

True when the page is empty or shorter than the requested page size.