-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathcloudstoragelistall.py
34 lines (26 loc) · 987 Bytes
/
cloudstoragelistall.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/python
# -*- coding: utf-8 -*-
# cloudstoragelistall.py
# It is an example that handles Cloud Storage buckets on Google Cloud Platform (GCP).
# List information about all Cloud Storage buckets and the objects that they contain.
# The credentials are taken from GOOGLE_APPLICATION_CREDENTIALS environment variable.
import sys
from google.cloud import storage
def main():
print('Listing Cloud Storage buckets and objects ...')
# Instantiate the client.
client = storage.Client()
# List all the buckets.
buckets = client.list_buckets()
for bucket in buckets:
print('* Bucket:', bucket.name)
# Lists all the blobs in the bucket.
blobs = bucket.list_blobs()
for blob in blobs:
print(' - Object:', blob.name)
print(' size:', blob.size)
print('\nListed')
return
# This is the standard boilerplate that calls the main() function.
if __name__ == '__main__':
main()