Pagination

class labelbox.pagination.PaginatedCollection(client: Client, query: str, params: Dict[str, str | int], dereferencing: List[str] | Dict[str, Any], obj_class: Type[DbObject] | Callable[[Any, Any], Any], cursor_path: List[str] | None = None, experimental: bool = False)[source]

Bases: object

An iterable collection of database objects (Projects, Labels, etc…).

Implements automatic (transparent to the user) paginated fetching during iteration. Intended for use by library internals and not by the end user. For a list of attributes see __init__(…) documentation. The params of __init__ map exactly to object attributes.

__init__(client: Client, query: str, params: Dict[str, str | int], dereferencing: List[str] | Dict[str, Any], obj_class: Type[DbObject] | Callable[[Any, Any], Any], cursor_path: List[str] | None = None, experimental: bool = False)[source]

Creates a PaginatedCollection.

Parameters:
  • client (labelbox.Client) – the client used for fetching data from DB.

  • query (str) – Base query used for pagination. It must contain two ‘%d’ placeholders, the first for pagination ‘skip’ clause and the second for the ‘first’ clause.

  • params (dict) – Query parameters.

  • dereferencing (iterable) – An iterable of str defining the keypath that needs to be dereferenced in the query result in order to reach the paginated objects of interest.

  • obj_class (type) – The class of object to be instantiated with each dict containing db values.

  • cursor_path – If not None, this is used to find the cursor

  • experimental – Used to call experimental endpoints

get_many(n: int)[source]

Iterates over self and returns first n results This method is idempotent

Parameters:

n (int) – Number of elements to retrieve

get_one()[source]

Iterates over self and returns first value This method is idempotent