Skip to content

Instantly share code, notes, and snippets.

@rcgalbo
Last active August 21, 2018 18:23
Show Gist options
  • Save rcgalbo/f801a890ead25d2ba4a993eb59c4af9e to your computer and use it in GitHub Desktop.
Save rcgalbo/f801a890ead25d2ba4a993eb59c4af9e to your computer and use it in GitHub Desktop.
list the contents of a gcs bucket
from google.cloud import storage
def list_blobs(bucket, prefix):
"""
Lists all the blobs in the bucket
make sure prefix ends with '/'
"""
storage_client = storage.Client()
bucket = storage_client.get_bucket(bucket)
blobs = bucket.list_blobs(prefix=prefix)
blob_list = [blob.name for blob in blobs]
return blob_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment