CursorPage

class trustar.models.cursor_page.CursorPage(items=None, response_metadata=None)

This class models a page of items that would be found in the body of a response from an endpoint that uses pagination. Unlike the Page class, it uses cursor-based pagination instead of number-based pagination.

Variables:
  • items – The list of items of the page; i.e. a list of indicators, reports, etc.
  • cursor – A Base64-encoded string that contains information on how to retrieve the next page. If a cursor isn’t passed, it will default to pageSize: 25, pageNumber: 0
  • total_elements – The total number of elements on the server, e.g. the total number of elements across all pages. Note that it is possible for this value to change between pages, since data can change between queries.
static from_dict(page, content_type=None)

Create a CursorPage object from a dictionary. This method is intended for internal use, to construct a CursorPage object from the body of a response json from a paginated endpoint.

Parameters:
  • page – The dictionary.
  • content_type – The class that the contents should be deserialized into.
Returns:

The resulting Page object.

static get_cursor_based_page_generator(get_page, cursor=None)

A page generator that uses cursor-based pagination.

Parameters:
  • get_page – a function to get the next page, given values for from_time and to_time
  • cursor – A Base64-encoded string that contains information on how to retrieve the next page. If a cursor isn’t passed, it will default to pageSize: 25, pageNumber: 0
Returns:

a generator that yields each successive page

to_dict(remove_nones=False)

Creates a dictionary representation of the page.

Parameters:remove_nones – Whether None values should be filtered out of the dictionary. Defaults to False.
Returns:A dictionary representation of the page.