python 和 google 云存储

python and google cloud storage

我无法找到如何使用 google 云存储而不 运行 在 google appengine 上使用它的示例。

我想要这样的东西(这对我很有用):https://github.com/GoogleCloudPlatform/storage-getting-started-javascript/ 但在 python 中实施。

所以我想要存档的是我的前端询问我的 python 后端,然后询问云存储。我找不到任何不使用 appengine 进行身份验证的示例,但这并非不可能。

我已经查看了 https://github.com/GoogleCloudPlatform/ 上的两个示例,但我找不到不依赖于 appengine 的示例。

它还必须在 python3 上 运行。

您可以使用 gsutil to access Google Cloud Storage from the command line. There is a getting started tutorial here.

有一个 Python 使用 gsutil 的示例 here:

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

google-api-python-client 是用于与 GCS 交互的官方 Python 客户端。

最近添加了

Python 3.x 支持,但需要注意:

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.

我认为这是一个很好的问题,因为除了 gsutil cli 之外还有很多 python 库。这似乎是 google

最新支持的 python 客户端

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

github 在这里

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

这是您要找的吗? blob 具有从文件下载、上传到文件的功能。使用这些函数,您几乎可以用 GCS 做任何事情

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()

少了几个功能,他们多了一些

download_to_filename
upload_from_file