psnawp_api.models.listing.pagination_iterator module#

Provides the PaginationIterator class.

class PaginationArguments(total_limit: int | None, page_size: int, offset: int)[source]#

Bases: object

Class representing the arguments PlayStation API needs for paginating over list items.

Used by the implementations of PaginationIterator.

Variables:
  • total_limit (int | None) – The maximum number of items to retrieve across all pages. If None, there is no limit.

  • page_size (int) – The number of items to fetch per page.

  • offset (int) – The starting index for fetching items.

__init__(total_limit: int | None, page_size: int, offset: int) None#
property adjusted_page_size: int#

Calculates the adjusted page size based on the total limit.

If total_limit is None, returns the original page_size. If total_limit is less than page_size, returns total_limit.

get_params_dict() dict[str, int][source]#

Converts the object into serializable dict that can be passed as HTTPs request param.

Returns:

dict containing pagination params

increment_offset() None[source]#

Helper method to increment the offset class member.

is_limit_reached() bool[source]#

Helper method to determine if we have reached end of pagination.

offset: int#
page_size: int#
total_limit: int | None#
class PaginationIterator(*, authenticator: Authenticator, url: str, pagination_args: PaginationArguments)[source]#

Bases: Iterator[T], Generic[T]

An iterator for paginated API endpoints.

This class simplifies pagination by handling iteration over API responses. Subclasses only need to implement the fetch_next_page() method, while this class manages the iteration logic.

Variables:
  • authenticator (Authenticator) – An instance of Authenticator used to authenticate and make HTTPS requests.

  • _url (str) – URL for the paginated endpoint.

  • _pagination_args (PaginationArguments) – Pagination-specific arguments, such as page size and limit, passed to the endpoint.

  • _per_page_iterator (Iterator[T] | None) – A generator that iterates over items in the fetched page.

  • _has_next (bool) – Indicates whether more pages are available. Is updated when fetch_next_page() is called.

  • _total_item_count (int) – The total number of items available in the paginated endpoint.

Warning

This class is not meant to be used directly.

Initialize the PaginationIterator instance.

Parameters:
  • authenticator – An instance of Authenticator for making API requests.

  • url – The URL of the endpoint.

  • pagination_args – Pagination-related arguments, such as page size and limit.

__init__(*, authenticator: Authenticator, url: str, pagination_args: PaginationArguments) None[source]#

Initialize the PaginationIterator instance.

Parameters:
  • authenticator – An instance of Authenticator for making API requests.

  • url – The URL of the endpoint.

  • pagination_args – Pagination-related arguments, such as page size and limit.

abstractmethod fetch_next_page() Iterator[T][source]#

Fetch the next page of items from the API.

Note

The implementation of this methods are also responsible for incrementing the offset using increment_offset(), setting the _total_item_count, and updating the _has_next.

set_offset(offset: int) None[source]#

Set the offset parameter for the API request.

Parameters:

offset – The offset value to set.

set_page_size(page_size: int) None[source]#

Set the page size (limit) parameter for the API request.

Parameters:

page_size – The page size value to set.