Paginator#
Summary#
|
Split an iterable into chunks of a max size |
|
Get all pages of a multi-page request. |
Module Contents#
- class pyinaturalist.paginator.AutocompletePaginator(*args, **kwargs)#
Bases:
pyinaturalist.paginator.Paginator
Paginator that attempts to get as many results as possible from an autocomplete endpoint. This is necessary for some problematic queries for which there are many matches but not ranked with the desired match(es) first.
This works based on different rankings being returned for order_by=area. No other fields can be sorted on, and direction can’t be specified, but this can at least provide a few additional results beyond the limit of 20.
All results will be de-duplicated and returned as a single page. This may potentially be applied to other autocomplete endpoints, but so far is only needed for places.
- class pyinaturalist.paginator.IDPaginator(*args, ids=None, ids_per_request=1, **kwargs)#
Bases:
pyinaturalist.paginator.Paginator
Paginator for ID-based endpoints that only accept a limited number of IDs per request
- class pyinaturalist.paginator.JsonPaginator(request_function, *request_args, **kwargs)#
Bases:
pyinaturalist.paginator.Paginator
Paginator that returns raw response dicts instead of model objects
- 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 paginatemodel (
Type
[TypeVar
(T
, bound= BaseModel)]) – Model class to use for resultsmethod (
str
) – Pagination method; either ‘page’ or ‘id’ (see note below)limit (
Optional
[int
]) – Maximum number of total results to fetchper_page (
Optional
[int
]) – Maximum number of results to fetch per pagekwargs – 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.
- count()#
Get the total number of results for this query, without fetching response data.
- Return type
- Returns
Either the total number of results, if the endpoint provides pagination info, or
-1
- next_page()#
Get the next page of results, as model objects
- class pyinaturalist.paginator.WrapperPaginator(results, *args, **kwargs)#
Bases:
pyinaturalist.paginator.Paginator
Paginator class that wraps results that have already been fetched.
- count()#
Get the total number of results for this query, without fetching response data.
- Return type
- Returns
Either the total number of results, if the endpoint provides pagination info, or
-1
- next_page()#
Get the next page of results, as model objects
- pyinaturalist.paginator.chunkify(iterable, max_size)#
Split an iterable into chunks of a max size