How can the number of blobs returned from ContainerClient.list_blobs() method can be limited?
The Azure Blob service RESP API docs mentions a maxresults parameter, but it seems it is not honored by list_blobs(maxresults=123).
How can the number of blobs returned from ContainerClient.list_blobs() method can be limited?
The Azure Blob service RESP API docs mentions a maxresults parameter, but it seems it is not honored by list_blobs(maxresults=123).
A combination of itertools.islice and the results_per_page parameter (which translates to the REST maxresults parameter) will do the trick:
import itertools
service: BlobServiceClient = BlobServiceClient.from_connection_string(cstr)
cc = service.get_container_client("foo")
n = 42
for b in itertools.islice(cc.list_blobs(results_per_page=n), n):
print(b.name)
Please use by_page() on the ItemPaged class
pages = ContainerClient.list_blobs(maxresults=123).by_page()
first_page = next(pages)
items_in_page = list(a_page) #this will give you 123 results on the first page
second_page = next(pages) # it will throw exception if there's no second page
items_in_page = list(a_page) #this will give you 123 results on the second page
There's no way to do this currently with the SDK. The maxresults parameter really means "max results per page"; if you have more blobs than this, list_blobs will make multiple calls to the REST API until the listing is complete.
You could call the API directly and ignore pages after the first, but that would require you to handle the details of authentication, parsing the response, etc.
results_per_page arg shows this is incorrectmaxresults (available in REST API) in Python SDK. results_per_page does exactly that.list_blobs()
results_per_pageoptions: github.com/Azure/azure-sdk-for-python/blob/master/sdk/eventhub/…