ds_protocol_http_py_lib.dataset.pagination.strategies.offset ============================================================ .. py:module:: ds_protocol_http_py_lib.dataset.pagination.strategies.offset .. autoapi-nested-parse:: **File:** ``offset.py`` **Region:** ``ds_protocol_http_py_lib/dataset/pagination/strategies/offset`` Offset / limit page strategy. When to use (arbitrary API) Pick this if the API asks for a **numeric skip** into the list, e.g. ``?offset=0&limit=100``, ``?skip=200&take=50``, ``from=100&size=100``. You (the client) compute the next window from the rows returned: ``offset += len(items)``. The next request still asks for ``page_size``. Prefer **cursor** instead when the same API also offers a next-token — offsets break under inserts/deletes between pages (skipped / duplicated rows). Prefer **page_number** if the API speaks in page indexes, not row offsets (``?page=2&per_page=50``). Intent Client-derived windows over a list. An empty page stops. When ``total_path`` resolves, a non-empty page stops once ``offset + len(items) >= total``. Otherwise a short page stops. Boundaries Owns page params, stop logic, and mid-run ``checkpoint["pagination"]`` (``offset``, ``limit``, ``page_index``). Does not own HTTP, watermarks, or clearing pagination on success — :class:`Paginate` does. Example:: PaginationSettings( strategy=PaginationStrategy.OFFSET, items_path="data", offset=OffsetPaginationSettings( page_size=100, total_path="meta.total", # optional ), ) Classes ------- .. autoapisummary:: ds_protocol_http_py_lib.dataset.pagination.strategies.offset.OffsetPaginationStrategy Module Contents --------------- .. py:class:: OffsetPaginationStrategy Bases: :py:obj:`ds_protocol_http_py_lib.dataset.pagination.strategies.base.PaginationStrategyHandler`\ [\ :py:obj:`ds_protocol_http_py_lib.dataset.pagination.settings.OffsetPaginationSettings`\ ] Client-derived offset pagination: ``offset(n+1) = offset(n) + len(items)``. .. py:method:: initial_state(cfg: ds_protocol_http_py_lib.dataset.pagination.settings.OffsetPaginationSettings, checkpoint_slice: dict[str, Any] | None) -> ds_protocol_http_py_lib.dataset.pagination.strategies.base.PageState Build the starting page state, optionally restoring from checkpoint. .. py:method:: 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.OffsetPaginationSettings) -> ds_protocol_http_py_lib.utils.http.request.RequestSnapshot Return a request snapshot with pagination values applied. .. py:method:: 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.OffsetPaginationSettings) -> ds_protocol_http_py_lib.dataset.pagination.strategies.base.PageState Advance state after a successful page response. .. py:method:: 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.OffsetPaginationSettings) -> bool Return True when traversal should terminate after this page. .. py:method:: to_checkpoint(state: ds_protocol_http_py_lib.dataset.pagination.strategies.base.PageState) -> dict[str, Any] Serialize traversal state into the checkpoint ``pagination`` slice. .. py:method:: from_checkpoint(data: dict[str, Any]) -> ds_protocol_http_py_lib.dataset.pagination.strategies.base.PageState Restore traversal state from a checkpoint ``pagination`` slice.