ds_protocol_http_py_lib.dataset.pagination.strategies.cursor¶
File: cursor.py
Region: ds_protocol_http_py_lib/dataset/pagination/strategies/cursor
Opaque cursor / token page strategy.
- When to use (arbitrary API)
Pick this if the API gives you the next position — a token in the body or a header — and expects you to send it back, e.g. response
{"data": [...], "next": "abc"}then request?cursor=abc, or headerLink: <...>; rel="next"/X-Next-Cursor. You do not compute the next page; you echo whatever the server returned until it returns none.Prefer this over offset/page whenever both exist: tokens stay correct when the list mutates between calls. Use offset or page_number only when the API has no continuation token and documents numeric skip or page index instead.
Note: mid-run resume stores the token in
checkpoint["pagination"]. If the API’s tokens expire across process restarts, drain in one run or pair with incremental windowing — this strategy does not invent a durable watermark.- Intent
Server-driven continuation. Stop when the next cursor is absent; raise if the cursor does not change (no progress).
- Boundaries
Owns cursor inject/extract, optional page-size query param, stop/progress checks, and mid-run
checkpoint["pagination"](cursor,page_size,page_index). Does not own HTTP, watermarks, or clearing pagination on success —Paginatedoes.
Example:
PaginationSettings(
strategy=PaginationStrategy.CURSOR,
items_path="data",
cursor=CursorPaginationSettings(
cursor_path="meta.next",
cursor_param="cursor",
page_size_param="limit",
page_size=100,
),
)
Classes¶
Opaque cursor pagination: echo the server token until it is absent. |
Functions¶
|
Module Contents¶
- ds_protocol_http_py_lib.dataset.pagination.strategies.cursor._read_next_cursor(body: Any, headers: Any, cfg: ds_protocol_http_py_lib.dataset.pagination.settings.CursorPaginationSettings) str | None[source]¶
- class ds_protocol_http_py_lib.dataset.pagination.strategies.cursor.CursorPaginationStrategy[source]¶
Bases:
ds_protocol_http_py_lib.dataset.pagination.strategies.base.PaginationStrategyHandler[ds_protocol_http_py_lib.dataset.pagination.settings.CursorPaginationSettings]Opaque cursor pagination: echo the server token until it is absent.
- initial_state(cfg: ds_protocol_http_py_lib.dataset.pagination.settings.CursorPaginationSettings, checkpoint_slice: dict[str, Any] | None) ds_protocol_http_py_lib.dataset.pagination.strategies.base.PageState[source]¶
Build the starting page state, optionally restoring from checkpoint.
- inject(request: ds_protocol_http_py_lib.utils.http.request.RequestSnapshot, state: ds_protocol_http_py_lib.dataset.pagination.strategies.base.PageState, cfg: ds_protocol_http_py_lib.dataset.pagination.settings.CursorPaginationSettings) ds_protocol_http_py_lib.utils.http.request.RequestSnapshot[source]¶
Return a request snapshot with pagination values applied.
- advance(*, body: Any, headers: Any, items: list[Any], state: ds_protocol_http_py_lib.dataset.pagination.strategies.base.PageState, cfg: ds_protocol_http_py_lib.dataset.pagination.settings.CursorPaginationSettings) ds_protocol_http_py_lib.dataset.pagination.strategies.base.PageState[source]¶
Advance state after a successful page response.
- should_stop(*, body: Any, headers: Any, items: list[Any], state: ds_protocol_http_py_lib.dataset.pagination.strategies.base.PageState, cfg: ds_protocol_http_py_lib.dataset.pagination.settings.CursorPaginationSettings) bool[source]¶
Return True when traversal should terminate after this page.
- to_checkpoint(state: ds_protocol_http_py_lib.dataset.pagination.strategies.base.PageState) dict[str, Any][source]¶
Serialize traversal state into the checkpoint
paginationslice.
- from_checkpoint(data: dict[str, Any]) ds_protocol_http_py_lib.dataset.pagination.strategies.base.PageState[source]¶
Restore traversal state from a checkpoint
paginationslice.