Paginator

Summary

paginate_all(request_function, *args[, method])

Get all pages of a multi-page request.

Module Contents

class pyinaturalist.paginator.IDPaginator(*args, ids=None, **kwargs)

Bases: pyinaturalist.paginator.Paginator

Paginator for endpoints that only accept a single ID per request

next_page()

Get the next record by ID

Return type

List[Dict[str, Any]]

class pyinaturalist.paginator.JsonPaginator(request_function, model, *request_args, method='page', limit=None, per_page=None, **kwargs)

Bases: pyinaturalist.paginator.Paginator

Paginator that returns raw response dicts instead of model objects

all()

Get all results in a single list

Return type

Dict[str, Any]

class pyinaturalist.paginator.Paginator(request_function, model, *request_args, method='page', limit=None, per_page=None, **kwargs)

Bases: Iterable, AsyncIterable, Generic[pyinaturalist.models.base.T]

Class to handle pagination of API requests, with async support

Parameters
  • request_function (Callable) – API request function to paginate

  • model (TypeVar(T, bound= BaseModel)) – Model class to use for results

  • method (str) – Pagination method; either ‘page’ or ‘id’ (see note below)

  • limit (Optional[int]) – Maximum number of results to fetch

  • per_page (Optional[int]) – Maximum number of results to fetch per page

  • kwargs – Original request parameters

Note

Note on pagination by ID, from the iNaturalist documentation:

The large size of the observations index prevents us from supporting the page parameter when retrieving records from large result sets. If you need to retrieve large numbers of records, use the ``per_page`` and ``id_above`` or ``id_below`` parameters instead.

all()

Get all results in a single list

Return type

List[TypeVar(T, bound= BaseModel)]

count()

Get the total number of results for this query, without fetching response data.

Return type

int

Returns

Either the total number of results, if the endpoint provides pagination info, or -1

next_page()

Get the next page of results

Return type

List[Dict[str, Any]]

one()

Get the first result from the query

Return type

Optional[TypeVar(T, bound= BaseModel)]

pyinaturalist.paginator.paginate_all(request_function, *args, method='page', **kwargs)

Get all pages of a multi-page request. Explicit pagination parameters will be overridden.

Return type

Dict[str, Any]

Returns

Response dict containing combined results, in the same format as api_func