Google 云存储的类似 Boto 的库

Boto-like library for Google Cloud Storage

Boto 提供了一种将文件上传到 Amazon S3 的简单方法:

conn = boto.connect_s3(settings.AWS_ACCESS_KEY, settings.AWS_SECRET_KEY)
bucket = conn.get_bucket(bucket) # my 'folder'
key = bucket.new_key(s3_filename) # my 'filename'
key.set_contents_from_filename('myfile.txt')

对于 Google Cloud Storage 和 python 是否有等效的方法来做同样的事情?我见过的所有示例都涉及 50 多行代码来执行 'simple' 操作,例如上传本地文件。

如何做到这一点(从 CLI)?

对于通过 Python 的程序使用,boto 库和 gcs-oauth2-boto-plugin 让您可以使用与 GCS 交互的基本相同的代码,就像您可以用于 S3(或可能是其他云存储)使用正确插件的服务)。

参见https://cloud.google.com/storage/docs/gspythonlibrary for instructions on how to download and install the library and plugin, and several short example snippets of Python code to perform various operations. Other detailed instructions are at https://cloud.google.com/storage/docs/gsutil_install#boto

CLI使用更简单;例如,一旦您安装并验证了 gsutil,典型的 "upload a bunch of files" CLI 命令就是

$ gsutil cp *.txt gs://my_bucket

(使用 $ 表示 "the shell prompt":-)。