Repository: googleapis/python-storage

Issue:
bucket.list_blobs is missing page_size arg (present in client.list_blobs)
For consistency, it would be great if bucket.list_blobs supported the page_size argument.

A work-around is to call client.list_blobs directly, where page_size is a valid arg.


Discussion:

Patch:
diff --git a/google/cloud/storage/bucket.py b/google/cloud/storage/bucket.py
index 2b42b81..15fb408 100644
--- a/google/cloud/storage/bucket.py
+++ b/google/cloud/storage/bucket.py
@@ -1308,6 +1308,7 @@ class Bucket(_PropertyMixin):
         match_glob=None,
         include_folders_as_prefixes=None,
         soft_deleted=None,
+        page_size=None,
     ):
         """Return an iterator used to find blobs in the bucket.
 
@@ -1401,6 +1402,11 @@ class Bucket(_PropertyMixin):
             Note ``soft_deleted`` and ``versions`` cannot be set to True simultaneously. See:
             https://cloud.google.com/storage/docs/soft-delete
 
+        :type page_size: int
+        :param page_size:
+            (Optional) Maximum number of blobs to return in each page.
+            Defaults to a value set by the API.
+
         :rtype: :class:`~google.api_core.page_iterator.Iterator`
         :returns: Iterator of all :class:`~google.cloud.storage.blob.Blob`
                   in this bucket matching the arguments.
@@ -1418,6 +1424,7 @@ class Bucket(_PropertyMixin):
             versions=versions,
             projection=projection,
             fields=fields,
+            page_size=page_size,
             timeout=timeout,
             retry=retry,
             match_glob=match_glob,


Test patch:
diff --git a/tests/unit/test_bucket.py b/tests/unit/test_bucket.py
index d8ce1e0..2df41c3 100644
--- a/tests/unit/test_bucket.py
+++ b/tests/unit/test_bucket.py
@@ -1179,6 +1179,7 @@ class Test_Bucket(unittest.TestCase):
         expected_fields = None
         expected_include_folders_as_prefixes = None
         soft_deleted = None
+        page_size = None
         client.list_blobs.assert_called_once_with(
             bucket,
             max_results=expected_max_results,
@@ -1196,6 +1197,7 @@ class Test_Bucket(unittest.TestCase):
             match_glob=expected_match_glob,
             include_folders_as_prefixes=expected_include_folders_as_prefixes,
             soft_deleted=soft_deleted,
+            page_size=page_size,
         )
 
     def test_list_blobs_w_explicit(self):
@@ -1211,6 +1213,7 @@ class Test_Bucket(unittest.TestCase):
         include_folders_as_prefixes = True
         versions = True
         soft_deleted = True
+        page_size = 2
         projection = "full"
         fields = "items/contentLanguage,nextPageToken"
         bucket = self._make_one(client=None, name=name)
@@ -1236,6 +1239,7 @@ class Test_Bucket(unittest.TestCase):
             match_glob=match_glob,
             include_folders_as_prefixes=include_folders_as_prefixes,
             soft_deleted=soft_deleted,
+            page_size=page_size,
         )
 
         self.assertIs(iterator, other_client.list_blobs.return_value)
@@ -1253,6 +1257,7 @@ class Test_Bucket(unittest.TestCase):
         expected_fields = fields
         expected_include_folders_as_prefixes = include_folders_as_prefixes
         expected_soft_deleted = soft_deleted
+        expected_page_size = page_size
         other_client.list_blobs.assert_called_once_with(
             bucket,
             max_results=expected_max_results,
@@ -1270,6 +1275,7 @@ class Test_Bucket(unittest.TestCase):
             match_glob=expected_match_glob,
             include_folders_as_prefixes=expected_include_folders_as_prefixes,
             soft_deleted=expected_soft_deleted,
+            page_size=expected_page_size,
         )
 
     def test_list_notifications_w_defaults(self):