ds_protocol_http_py_lib.dataset.pagination.strategies.offset

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 — Paginate does.

Example:

PaginationSettings(
    strategy=PaginationStrategy.OFFSET,
    items_path="data",
    offset=OffsetPaginationSettings(
        page_size=100,
        total_path="meta.total",  # optional
    ),
)

Classes

OffsetPaginationStrategy

Client-derived offset pagination: offset(n+1) = offset(n) + len(items).

Module Contents

class ds_protocol_http_py_lib.dataset.pagination.strategies.offset.OffsetPaginationStrategy[source]

Bases: ds_protocol_http_py_lib.dataset.pagination.strategies.base.PaginationStrategyHandler[ds_protocol_http_py_lib.dataset.pagination.settings.OffsetPaginationSettings]

Client-derived offset pagination: offset(n+1) = offset(n) + len(items).

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[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.OffsetPaginationSettings) → 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.OffsetPaginationSettings) → 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.OffsetPaginationSettings) → 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 pagination slice.

from_checkpoint(data: dict[str, Any]) → ds_protocol_http_py_lib.dataset.pagination.strategies.base.PageState[source]

Restore traversal state from a checkpoint pagination slice.