Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python and google cloud storage

I can't find an example of how to use the google cloud storage WITHOUT running it on google appengine.

I want something like this (which works good for me): https://github.com/GoogleCloudPlatform/storage-getting-started-javascript/ but implemented in python instead.

So what I want to archive is that my frontend asks my python backend which then asks the cloud storage. I can't seam to find any examples that doesn't use appengine to authenticate, but it cant be impossible.

I've looked at both a couple of examples on https://github.com/GoogleCloudPlatform/ but i can't find one without dependencies on appengine.

It also has to run on python3.

like image 664
Jonathan Anderson Avatar asked May 06 '15 12:05

Jonathan Anderson


2 Answers

is this what you are looking for? blob has functions to download from file, upload to a file. You can do pretty much everything with GCS using these functions

from google.cloud import storage
client = storage.Client()
bucket = client.get_bucket('bucket-name')
blob = bucket.get_blob('path-to-file')
data = blob.download_as_string()

few more functions, they have some more

download_to_filename
upload_from_file
like image 100
user9484528 Avatar answered Nov 03 '22 08:11

user9484528


You can use gsutil to access Google Cloud Storage from the command line. There is a getting started tutorial here.

There is a Python example using gsutil here:

This tutorial shows you how to write a simple Python program that performs basic Google Cloud Storage operations using the XML API.

like image 37
Peter Wood Avatar answered Nov 03 '22 09:11

Peter Wood