paginated#

@fitrequest.decorators.paginated.paginated[source]#

Decorator that automatically handles pagination for an endpoint. Combines all page results into one merged result instead of requiring manual handling. Custom behavior can be implemented by providing a specific AbstractPage subclass.

class fitrequest.decorators.paginated.AbstractPage(data: Any)[source]#

Bases: ABC

Represents a paginated request page with methods to access results and navigation. This structure must be overridden to customize behavior for different API responses.

classmethod async_iterator(get_page: Callable) AsyncIterator[AbstractPage][source]#

Creates an async iterator that retrieves all pages using the provided fitrequest method.

async classmethod async_merge_results(get_page: Callable) list[source]#

Combines all paginated results into a single merged list. Uses the provided fitrequest function to fetch pages and merges their results.

abstractmethod async static async_save_results(filepath: Path, results: list[AbstractPage]) None[source]#

Saves the list of page objects to the specified file path.

data: Any#
classmethod iterator(get_page: Callable) Iterator[AbstractPage][source]#

Creates an iterator that retrieves all pages using the provided fitrequest method.

classmethod merge_results(get_page: Callable) list[source]#

Combines all paginated results into a single merged list. Uses the provided fitrequest function to fetch pages and merges their results.

abstract property next_url: str | None#

Returns the URL for the next page if available, otherwise returns None.

abstract property results: Iterable#

Returns the iterable result extracted from the raw page data.

abstractmethod static save_results(filepath: Path, results: list[AbstractPage]) None[source]#

Saves the list of page objects to the specified file path.

class fitrequest.decorators.paginated.PageDict(data: Any, results_kw: str = 'results', next_kw: str = 'next')[source]#

Bases: AbstractPage

Specific implementation of pagination where the requests raw data is a dictionary containing two keywords:

  • result: Iterable data for current page

  • next: URL for next page

async static async_save_results(filepath: Path, results: list) None[source]#

Saves the list of page objects to the specified file path.

next_kw: str = 'next'#
property next_url: str | None#

Returns the URL for the next page if available, otherwise returns None.

property results: Iterable#

Returns the iterable result extracted from the raw page data.

results_kw: str = 'results'#
static save_results(filepath: Path, results: list) None[source]#

Saves the list of page objects to the specified file path.