I want to get a list of all the blobs in a Google Cloud Storage bucket using the Client Library for Python.
According to the documentation I should use the list_bl
list_blobs()
does use paging, but you do not use page_token
to achieve it.
The way list_blobs()
work is that it returns an iterator that iterates through all the results doing paging behind the scenes. So simply doing this will get you through all the results, fetching pages as needed:
for blob in bucket.list_blobs()
print blob.name
As of 04/26/2017 this is what the docs says:
page_token
(str) – (Optional) Opaque marker for the next “page” of blobs. If not passed, will return the first page of blobs.
This implies that the result will be a single page of results with page_token
determining which page. This is not correct. The result iterator iterates through multiple pages. What page_token
actually represents is which page the iterator should START at. It no page_token
is provided it will start at the first page.
max_results
limits the total number of results returned by the iterator.
The iterator does expose pages if you need it:
for page in bucket.list_blobs().pages:
for blob in page:
print blob.name