使用标准的gcloud库,该库同时支持Python 2和Python 3。
将文件上传到云存储的示例
from gcloud import storagefrom oauth2client.service_account import ServiceAccountCredentialsimport oscredentials_dict = { 'type': 'service_account', 'client_id': os.environ['BACKUP_CLIENT_ID'], 'client_email': os.environ['BACKUP_CLIENT_EMAIL'], 'private_key_id': os.environ['BACKUP_PRIVATE_KEY_ID'], 'private_key': os.environ['BACKUP_PRIVATE_KEY'],}credentials = ServiceAccountCredentials.from_json_keyfile_dict( credentials_dict)client = storage.Client(credentials=credentials, project='myproject')bucket = client.get_bucket('mybucket')blob = bucket.blob('myfile')blob.upload_from_filename('myfile')


