ds_protocol_graphql_py_lib.dataset.pagination ============================================= .. py:module:: ds_protocol_graphql_py_lib.dataset.pagination .. autoapi-nested-parse:: **File:** ``__init__.py`` **Region:** ``ds_protocol_graphql_py_lib/dataset/pagination`` Pagination for GraphqlDataset reads. Importing this package registers the built-in strategies. .. rubric:: Example >>> from ds_protocol_graphql_py_lib.dataset.pagination import ( ... CursorPaginationSettings, ... PaginationSettings, ... PaginationStrategy, ... ) Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/ds_protocol_graphql_py_lib/dataset/pagination/enums/index /autoapi/ds_protocol_graphql_py_lib/dataset/pagination/paginate/index /autoapi/ds_protocol_graphql_py_lib/dataset/pagination/registry/index /autoapi/ds_protocol_graphql_py_lib/dataset/pagination/settings/index /autoapi/ds_protocol_graphql_py_lib/dataset/pagination/strategies/index Classes ------- .. autoapisummary:: ds_protocol_graphql_py_lib.dataset.pagination.PaginationStrategy ds_protocol_graphql_py_lib.dataset.pagination.Paginate ds_protocol_graphql_py_lib.dataset.pagination.CursorPaginationSettings ds_protocol_graphql_py_lib.dataset.pagination.PaginationSettings Functions --------- .. autoapisummary:: ds_protocol_graphql_py_lib.dataset.pagination.get_strategy ds_protocol_graphql_py_lib.dataset.pagination.register Package Contents ---------------- .. py:class:: PaginationStrategy Bases: :py:obj:`enum.StrEnum` Declared pagination mechanisms supported by GraphqlDataset. .. py:attribute:: CURSOR :value: 'cursor' Opaque cursor pagination (Relay ``first`` / ``after`` and similar). .. py:class:: Paginate(strategy: ds_protocol_graphql_py_lib.dataset.pagination.strategies.base.PaginationStrategyHandler[Any], read_settings: ds_protocol_graphql_py_lib.dataset.graphql.GraphqlReadSettings, pagination: ds_protocol_graphql_py_lib.dataset.pagination.settings.PaginationSettings, incremental_rules: ds_protocol_graphql_py_lib.dataset.incremental.rules.IncrementalRules | None = None, incremental: ds_protocol_graphql_py_lib.dataset.incremental.settings.IncrementalSettings | None = None) Composer for a paginated ``GraphqlDataset.read``. Resolves a registered page strategy and optional incremental ruleset, then drains pages. Strategy hooks supply page variation only; incremental rules supply the lower bound and advance the watermark. This class owns transport, GraphQL error checks, deserialization, the ``checkpoint["pagination"]`` slice, and error mapping. .. py:attribute:: strategy .. py:attribute:: read_settings .. py:attribute:: pagination .. py:attribute:: incremental_rules :type: ds_protocol_graphql_py_lib.dataset.incremental.rules.IncrementalRules .. py:attribute:: incremental :value: None .. py:method:: from_dataset(dataset: ds_protocol_graphql_py_lib.dataset.graphql.GraphqlDataset[Any, Any]) -> Paginate :classmethod: Build from ``dataset.settings.read`` and the strategy / rules registries. :raises ValueError: If ``settings.read.pagination`` is not configured. .. py:property:: records_path :type: str ``read.records_path``, falling back to ``items_path``. :type: Output record path .. py:method:: run(dataset: ds_protocol_graphql_py_lib.dataset.graphql.GraphqlDataset[Any, Any]) -> None Prepare → drain → assign ``output`` / checkpoint. Incremental ``prepare`` injects the stored watermark (if any) into the base request before the first page; ``observe`` records each fetched page (the pending watermark max) as the drain goes. On full success: ``output`` is all pages of this call, incremental ``commit`` advances ``checkpoint["incremental"]`` (including what earlier failed attempts observed), then ``checkpoint["pagination"]`` is cleared. On failure (including a failing ``commit``): ``output`` holds the pages fetched so far, ``checkpoint["pagination"]`` is kept, and the watermark is unchanged. :raises ReadError: On any GraphQL, transport, paging-control, or parse failure. :raises ConnectionError / AuthenticationError / AuthorizationError: Re-raised as-is. .. py:method:: drain(dataset: ds_protocol_graphql_py_lib.dataset.graphql.GraphqlDataset[Any, Any], request: ds_protocol_graphql_py_lib.dataset.request.GraphqlRequestSnapshot, frames: list[pandas.DataFrame] | None = None) -> list[pandas.DataFrame] Page loop via strategy hooks; write mid-run ``checkpoint["pagination"]``. Appends page frames to ``frames`` so callers keep partial output when this method raises mid-drain. :raises ValueError: If the checkpoint strategy mismatches. :raises ReadError: If GraphQL returns errors or ``max_pages`` is exceeded. .. py:method:: _snapshot(dataset: ds_protocol_graphql_py_lib.dataset.graphql.GraphqlDataset[Any, Any]) -> ds_protocol_graphql_py_lib.dataset.request.GraphqlRequestSnapshot Build an isolated request from settings; caller variables are deep-copied. .. py:method:: _validate_checkpoint_strategy(checkpoint_slice: Any, expected: str) -> None :staticmethod: .. py:method:: _concat_frames(frames: list[pandas.DataFrame]) -> pandas.DataFrame :staticmethod: Concatenate page frames, or return an empty frame when none were fetched. .. py:function:: get_strategy(strategy: ds_protocol_graphql_py_lib.dataset.pagination.enums.PaginationStrategy) -> ds_protocol_graphql_py_lib.dataset.pagination.strategies.base.PaginationStrategyHandler[Any] Resolve a registered strategy handler. :raises KeyError: If no handler is registered for ``strategy``. .. py:function:: register(strategy: ds_protocol_graphql_py_lib.dataset.pagination.enums.PaginationStrategy) -> collections.abc.Callable[[T], T] 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. :raises ValueError: If ``strategy`` is already registered. .. py:class:: CursorPaginationSettings Bases: :py:obj:`ds_common_serde_py_lib.Serializable` Configuration for cursor pagination via GraphQL variables. .. py:attribute:: cursor_path :type: str Dotted path on the full response body to the next cursor. Examples: ``data.x.pageInfo.endCursor`` (Relay ``endCursor``), or ``data.x.edges.-1.cursor`` for the cursor on the last edge when the API has no ``endCursor`` (e.g. Xledger). ``-1`` is the last list element; on an empty page it resolves to no cursor. .. py:attribute:: cursor_variable :type: str :value: 'after' GraphQL variable that receives the cursor. .. py:attribute:: page_size_variable :type: str | None :value: 'first' GraphQL variable that receives the page size. ``None`` to not send one. .. py:attribute:: page_size :type: int | None :value: 100 Requested page size. Never clamped; server rejections surface as errors. .. py:attribute:: has_next_path :type: str | None :value: None Optional path on the full response to a boolean "more pages" flag (e.g. ``data.x.pageInfo.hasNextPage``). When set, traversal stops when it is ``false``. When unset, traversal stops on an empty page or a missing / empty next cursor. .. py:class:: PaginationSettings Bases: :py:obj:`ds_common_serde_py_lib.Serializable` Declared pagination mechanism and strategy-specific nest. Provide the nest matching ``strategy``. Absence of ``PaginationSettings`` on ``GraphqlReadSettings`` means a single request. .. py:attribute:: strategy :type: ds_protocol_graphql_py_lib.dataset.pagination.enums.PaginationStrategy Pagination mechanism. Declared explicitly; never inferred. .. py:attribute:: items_path :type: str Path on the full response to the page's record list, used for paging control (empty-page checks). Missing or null is an error. Also the default ``records_path`` for output when that is unset. .. py:attribute:: max_pages :type: int | None :value: None Optional safety ceiling on pages fetched per ``read()``. Exceeding it raises. Counted per call: a read that resumes from ``checkpoint["pagination"]`` may fetch up to ``max_pages`` more pages, so a large source drains over several runs. .. py:attribute:: cursor :type: CursorPaginationSettings | None :value: None Required when ``strategy`` is ``cursor``. .. py:method:: __post_init__() -> None .. py:method:: _selected_nest() -> CursorPaginationSettings | None .. py:property:: strategy_config :type: CursorPaginationSettings Strategy-specific nest for ``strategy`` (guaranteed by ``__post_init__``).