octo_api.pagination

Class for handling paginated API responses.

Classes:

OctoResponse

TypedDict representing the raw JSON data returned by the Octopus Energy API.

PaginatedResponse(query_url[, query_params, …])

Represents a multi-page response from a REST API.

typeddict OctoResponse[source]

Bases: TypedDict

TypedDict representing the raw JSON data returned by the Octopus Energy API.

Required Keys
  • count (int) – The total number of responses.

  • next (str) – The URL of the next page of results.

  • previous (str) – The URL of the previous page of results.

  • results (List[Dict[str, Any]]) – The current page of results.

class PaginatedResponse(query_url, query_params=None, obj_type=<class 'dict'>)[source]

Bases: Iterable[~_T]

Represents a multi-page response from a REST API.

The items within the response can be iterated over or accessed by their indices. The total number of items can be accessed with len(response).

Parameters

Note

This class assumes the JSON response is in the format used by Django REST framework.

The response should be in the following format:

{
    "count": 1023,
    "next": "https://api.example.org/accounts/?page=5",
    "previous": "https://api.example.org/accounts/?page=3",
    "results": []
}

See https://www.django-rest-framework.org/api-guide/pagination/ for more information.

Methods:

__eq__(other)

Return self == other.

__getitem__(item)

Returns the item or items in the PaginatedResponse, as given by the index or slice.

__iter__()

Iterate over items in the PaginatedResponse.

__len__()

Returns the number of items in the PaginatedResponse.

__eq__(other)[source]

Return self == other.

Return type

bool

__getitem__(item)[source]

Returns the item or items in the PaginatedResponse, as given by the index or slice.

Parameters

item (Union[int, slice])

Return type

Union[~_T, List[~_T]]

Overloads
__iter__()[source]

Iterate over items in the PaginatedResponse.

Return type

Iterator[~_T]

__len__()[source]

Returns the number of items in the PaginatedResponse.

Return type

int