Skip to content

Instantly share code, notes, and snippets.

@justinnaldzin
Created April 25, 2018 03:04
Show Gist options
  • Save justinnaldzin/160df79a0579d264f8edb632fdbc259c to your computer and use it in GitHub Desktop.
Save justinnaldzin/160df79a0579d264f8edb632fdbc259c to your computer and use it in GitHub Desktop.
Define Google Cloud Storage bucket (create bucket if it doesn't exist)
from google.cloud import storage
# Define Google Cloud Storage bucket
storage_client = storage.Client()
bucket = storage_client.lookup_bucket(bucket_name)
if bucket:
print("Using bucket '{}'.".format(bucket.name))
else:
# Create Google Cloud Storage bucket if it doesn't exist
print("Bucket '{}' doesn't exist. Creating bucket...".format(bucket_name))
bucket = storage_client.create_bucket(bucket_name)
print("Using bucket '{}'.".format(bucket.name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment