Skip to content

DevSite Import: Pagination #685

Closed
Closed

Description

@grant

Notice: This DevSite page will soon be deleted per b/133171590. Please add this sample to GitHub if it is relevant still:

https://developers.google.com/api-client-library/python/guide/pagination


Pagination

Some API methods may return very large lists of data. To reduce the response size, many of these API methods support pagination. With paginated results, your application can iteratively request and process large lists one page at a time. For API methods that support it, there exist similarly named methods with a "_next" suffix. For example, if a method is named list(), there may also be a method named list_next(). These methods can be found in the API's PyDoc documentation on the Supported APIs page.

To process the first page of results, create a request object and call execute() as you normally would. For further pages, you call the corresponding method_name_next() method, and pass it the previous request and response. Continue paging until method_name_next() returns None.

In the following code snippet, the paginated results of a Google Plus activities list() method are processed:

activities = service.activities()
request = activities.list(userId='someUserId', collection='public')

while request is not None:
  activities_doc = request.execute(http=http)

  # Do something with the activities

  request = activities.list_next(request, activities_doc)

Note that you only call execute() on the request once inside the while loop.

Activity

  1. added
    type: docsImprovement to the documentation for an API.
    and removed
    triage meI really want to be triaged.
    on Jun 10, 2019
  2. added a commit that references this issue on Jun 26, 2019
    a73a4be
  3. grant commented on Jun 26, 2019

    @grant
    ContributorAuthor

    The docs are now added to the docs/ folder.
    Fixed with #706.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type: docsImprovement to the documentation for an API.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions