简体   繁体   中英

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.

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.

The google-api-python-client is the official Python client for interacting with GCS.

Python 3.x support was recently added, with the caveat:

Python 3.3+ is also now supported! However, this library has not yet been used as thoroughly with Python 3, so we'd recommend testing before deploying with Python 3 in production.

I think this is a good question as there are a lot of python libraries floating around in addition to the gsutil cli. This seems to be the latest supported python client by google

https://cloud.google.com/storage/docs/reference/libraries#client-libraries-install-python

and the github is here

https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/storage/cloud-client

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM