Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit 46a5728

Browse files
samples: add samples for partial list bucket (#1627)
Add samples for the partial list bucket feature. --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent af2d1f1 commit 46a5728

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2025 Google Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the 'License');
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# [START storage_list_buckets_partial_success]
18+
from google.cloud import storage
19+
20+
21+
def list_buckets_with_partial_success():
22+
"""Lists buckets and includes unreachable buckets in the response."""
23+
24+
storage_client = storage.Client()
25+
26+
buckets_iterator = storage_client.list_buckets(return_partial_success=True)
27+
28+
for page in buckets_iterator.pages:
29+
if page.unreachable:
30+
print("Unreachable locations in this page:")
31+
for location in page.unreachable:
32+
print(location)
33+
34+
print("Reachable buckets in this page:")
35+
for bucket in page:
36+
print(bucket.name)
37+
38+
39+
# [END storage_list_buckets_partial_success]
40+
41+
42+
if __name__ == "__main__":
43+
list_buckets_with_partial_success()

0 commit comments

Comments
 (0)