Source code for zapi.infrastructure.http.pagination

from __future__ import annotations
from typing import Iterator




[docs] def yield_pages(get_json, first_path: str, base_url: str) -> Iterator[dict]: """ Generic pager. get_json is a callable like http.get that returns a dict. Yields the full page payload dict so callers can choose the list key. """ path = first_path while path: data = get_json(path) yield data path = next_link(data, base_url)
[docs] def yield_items(get_json, first_path: str, base_url: str, items_key: str) -> Iterator[dict]: """ Convenience iterator that yields individual items from a list key. """ for page in yield_pages(get_json, first_path, base_url): for obj in page.get(items_key, []) or []: yield obj