Pagination

Certain API operations return lists of objects. When the number of objects in the list is large, the API will paginate the results.

The Files.com Python SDK provides multiple ways to paginate through lists of objects.

Automatic Pagination

The auto_paging_iter method yields every item in the list, loading each following page only when the items before it have been consumed. Stopping early, such as with break, requests no further pages.

Example Request

import files_sdk

try:
  for item in files_sdk.folder.list_for("remote/path/to/folder").auto_paging_iter():
    print(item.type, item.path)
except files_sdk.error.NotAuthenticatedError as err:
  print(f"Authentication Error Occurred ({type(err).__name__}):", err)
except files_sdk.error.Error as err:
  print(f"Unknown Error Occurred ({type(err).__name__}):", err)

Manual Pagination

Iterating a list object yields the items on its current page. has_next_page reports whether another page is available, and load_next_page replaces the current page with the next one. After the last page, load_next_page makes no request and keeps the last page in place.

Example Request

import files_sdk

try:
  list_obj = files_sdk.folder.list_for("remote/path/to/folder")
  
  while True:
    for item in list_obj:
      print(item.type, item.path)
    if not list_obj.has_next_page:
      break
    list_obj.load_next_page()
except files_sdk.error.NotAuthenticatedError as err:
  print(f"Authentication Error Occurred ({type(err).__name__}):", err)
except files_sdk.error.Error as err:
  print(f"Unknown Error Occurred ({type(err).__name__}):", err)