ds_protocol_http_py_lib.dataset.pagination

File: __init__.py Region: ds_protocol_http_py_lib/dataset/pagination

HTTP dataset pagination: settings, enums, strategy registry, and Paginate composer.

Submodules

Classes

ExtractSource

Where a pagination value is read from the response.

PaginationStrategy

Declared pagination mechanisms supported by HttpDataset.

Paginate

Composer for a paginated HttpDataset.read.

CursorPaginationSettings

Configuration for opaque cursor / token pagination.

OffsetPaginationSettings

Configuration for offset / limit pagination.

PageNumberPaginationSettings

Configuration for page-number / page-size pagination.

PaginationSettings

Declared pagination mechanism and strategy-specific nests.

CursorPaginationStrategy

Opaque cursor pagination: echo the server token until it is absent.

OffsetPaginationStrategy

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

PageNumberPaginationStrategy

Client-derived page ordinal pagination: page(n+1) = page(n) + 1.

PaginationStrategyHandler

Page-variation contract parameterized by the strategy settings nest.

Functions

get_strategy(...)

Resolve a registered strategy handler.

register(→ collections.abc.Callable[[T], T])

Class decorator that registers a strategy handler.

Package Contents

class ds_protocol_http_py_lib.dataset.pagination.ExtractSource[source]

Bases: enum.StrEnum

Where a pagination value is read from the response.

BODY = 'body'

JSON response body path.

HEADER = 'header'

Response header name.

class ds_protocol_http_py_lib.dataset.pagination.PaginationStrategy[source]

Bases: enum.StrEnum

Declared pagination mechanisms supported by HttpDataset.

OFFSET = 'offset'

Offset / limit pagination.

PAGE_NUMBER = 'page_number'

Page ordinal / page size pagination.

CURSOR = 'cursor'

Opaque cursor / token pagination.

class ds_protocol_http_py_lib.dataset.pagination.Paginate(strategy: ds_protocol_http_py_lib.dataset.pagination.strategies.base.PaginationStrategyHandler[Any], pagination: ds_protocol_http_py_lib.dataset.pagination.settings.PaginationSettings, incremental_rules: ds_protocol_http_py_lib.dataset.incremental.rules.IncrementalRules, incremental: ds_protocol_http_py_lib.dataset.incremental.settings.IncrementalSettings | None)[source]

Composer for a paginated HttpDataset.read.

Resolves a registered page strategy and optional incremental ruleset, then runs prepare → drain → commit. Strategy hooks supply page variation only; this class owns HTTP, checkpoint pagination slice, and error mapping.

strategy
pagination
incremental_rules
incremental
classmethod from_dataset(dataset: ds_protocol_http_py_lib.dataset.http.HttpDataset[Any, Any]) → Paginate[source]

Build from dataset.settings.read and the strategy / rules registries.

run(dataset: ds_protocol_http_py_lib.dataset.http.HttpDataset[Any, Any]) → None[source]

Prepare → drain → assign output / checkpoint.

On full success: clear checkpoint["pagination"], then incremental commit if configured. On failure: assign partial output, keep mid-run pagination resume, hold watermark.

drain(dataset: ds_protocol_http_py_lib.dataset.http.HttpDataset[Any, Any], request: ds_protocol_http_py_lib.utils.http.request.RequestSnapshot, frames: list[pandas.DataFrame] | None = None) → list[pandas.DataFrame][source]

Page loop via strategy hooks; write mid-run checkpoint["pagination"].

Appends page frames to frames (created if omitted) so callers retain partial output when this method raises mid-drain.

Each frame is dataset.deserializer(response.content) — the API body the caller configured the deserializer for. items_path is paging control only. An empty body is an empty frame and does not call the deserializer.

Raises:
  • ValueError – If dataset.deserializer is missing.

  • ReadError – If max_pages is exceeded without a natural stop.

_snapshot(dataset: ds_protocol_http_py_lib.dataset.http.HttpDataset[Any, Any]) → ds_protocol_http_py_lib.utils.http.request.RequestSnapshot[source]

Build an isolated request copy from dataset settings.

static _validate_checkpoint_strategy(checkpoint_slice: dict[str, Any] | None, expected: str) → None[source]
static _concat_frames(frames: list[pandas.DataFrame]) → pandas.DataFrame[source]

Concatenate page frames, or return an empty frame when none were fetched.

ds_protocol_http_py_lib.dataset.pagination.get_strategy(strategy: ds_protocol_http_py_lib.dataset.pagination.enums.PaginationStrategy) → ds_protocol_http_py_lib.dataset.pagination.strategies.base.PaginationStrategyHandler[Any][source]

Resolve a registered strategy handler.

Raises:

KeyError – If no handler is registered for strategy.

ds_protocol_http_py_lib.dataset.pagination.register(strategy: ds_protocol_http_py_lib.dataset.pagination.enums.PaginationStrategy) → collections.abc.Callable[[T], T][source]

Class decorator that registers a strategy handler.

Adding a new strategy is backward compatible: register a new enum member and handler module without changing Paginate.

class ds_protocol_http_py_lib.dataset.pagination.CursorPaginationSettings[source]

Bases: ds_common_serde_py_lib.Serializable

Configuration for opaque cursor / token pagination.

cursor_path: str

Body path or header name where the next cursor is read.

cursor_source: ds_protocol_http_py_lib.dataset.pagination.enums.ExtractSource

Whether the cursor is extracted from the response body or a header.

cursor_param: str = 'cursor'

Parameter / header / body key used to inject the cursor.

cursor_location: ds_protocol_http_py_lib.utils.http.request.InjectLocation

Where the cursor is injected on the next request.

page_size_param: str | None = None

Optional page-size query parameter name (always injected as QUERY).

page_size: int | None = None

Optional requested page size (sent with page_size_param).

class ds_protocol_http_py_lib.dataset.pagination.OffsetPaginationSettings[source]

Bases: ds_common_serde_py_lib.Serializable

Configuration for offset / limit pagination.

offset_param: str = 'offset'

Query/body/header parameter name for the offset.

limit_param: str = 'limit'

Query/body/header parameter name for the page size.

page_size: int = 100

Number of records requested per page.

initial_offset: int = 0

Offset used for the first page when no checkpoint exists.

total_path: str | None = None

Optional body path to a total record count.

When the path resolves, a non-empty page stops once offset + len(items) >= total. The next offset advances by the rows returned, and the request still asks for page_size. An empty page stops immediately. A short page ends the read only when this path is unset or missing.

inject_location: ds_protocol_http_py_lib.utils.http.request.InjectLocation

Where offset and limit are injected on the request.

class ds_protocol_http_py_lib.dataset.pagination.PageNumberPaginationSettings[source]

Bases: ds_common_serde_py_lib.Serializable

Configuration for page-number / page-size pagination.

page_param: str = 'page'

Parameter name for the page ordinal.

page_size_param: str = 'per_page'

Parameter name for the page size.

page_size: int = 100

Number of records requested per page.

start_page: int = 1

First page ordinal (0- or 1-based, must match the API).

total_pages_path: str | None = None

Optional body path to a total page count.

When the path resolves, a non-empty page stops on the last ordinal. An empty page stops immediately. A short page ends the read only when this path is unset or missing.

inject_location: ds_protocol_http_py_lib.utils.http.request.InjectLocation

Where page and page size are injected on the request.

class ds_protocol_http_py_lib.dataset.pagination.PaginationSettings[source]

Bases: ds_common_serde_py_lib.Serializable

Declared pagination mechanism and strategy-specific nests.

Provide the nest matching strategy (same pattern as auth nests on HttpLinkedServiceSettings). Other nests should be omitted from the payload; only the selected nest is read at runtime.

strategy: ds_protocol_http_py_lib.dataset.pagination.enums.PaginationStrategy

Pagination mechanism. Declared explicitly; never inferred.

max_pages: int | None = None

Optional client-side safety ceiling on pages fetched per read().

None (default) means no ceiling — keep paging until the strategy signals stop (short page, total count, empty cursor, …). Set an int only when you want a hard guard against runaway loops.

items_path: str = 'data'

Path to the record array used for paging control (stop / advance).

Use $ for a root array. Does not select what the deserializer sees. Each page frame is dataset.deserializer(response.content).

offset: OffsetPaginationSettings | None = None

Required when strategy is offset.

page_number: PageNumberPaginationSettings | None = None

Required when strategy is page_number.

cursor: CursorPaginationSettings | None = None

Required when strategy is cursor.

__post_init__() → None[source]
_selected_nest() → StrategyConfig | None[source]
property strategy_config: StrategyConfig

Strategy-specific nest for strategy (guaranteed by __post_init__).

class ds_protocol_http_py_lib.dataset.pagination.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 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.

class ds_protocol_http_py_lib.dataset.pagination.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.

class ds_protocol_http_py_lib.dataset.pagination.PageNumberPaginationStrategy[source]

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

Client-derived page ordinal pagination: page(n+1) = page(n) + 1.

initial_state(cfg: ds_protocol_http_py_lib.dataset.pagination.settings.PageNumberPaginationSettings, 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.PageNumberPaginationSettings) → 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.PageNumberPaginationSettings) → 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.PageNumberPaginationSettings) → 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.

class ds_protocol_http_py_lib.dataset.pagination.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.