跳转到主要内容

Google Cloud Storage Python客户端

项目描述

GCS-Client

https://img.shields.io/travis/Akrog/gcs-client.svg https://img.shields.io/pypi/v/gcs-client.svg https://img.shields.io/coveralls/Akrog/gcs-client/master.svg Documentation Status https://img.shields.io/pypi/pyversions/gcs-client.svg https://img.shields.io/:license-apache-blue.svg

Google Cloud Storage Python客户端

想法是创建一个具有类似功能的客户端,类似于 Google的appengine-gcs-client,但旨在用于在Google AppEngine之外运行的应用程序。

Cloud Storage文档可以在 Google 找到

功能

目前只提供基本功能

  • 创建存储桶

  • 删除存储桶

  • 列出项目中的存储桶

  • 获取项目的默认存储桶

  • 获取存储桶属性

  • 列出存储桶中的对象

  • 获取对象的属性

  • 删除对象

  • 读取对象内容

  • 写入对象

  • 可配置的带截断指数退避的重试

安装

要安装,只需运行

$ pip install --upgrade gcs-client

用法示例

要在项目中使用gcs-client,您需要有权访问目标Google Cloud Storage的凭据。

凭据由项目API管理器的 Google开发者控制台 中的 凭据部分 生成。建议的凭据文件是JSON。

一旦您有了凭据,您就可以开始使用gcs_client来访问您的项目

import gcs_client

credentials = gcs_client.Credentials('private_key.json')
project = gcs_client.Project('project_name', credentials)

# Print buckets in the project
buckets = project.list()
print 'Buckets:\n\t-', '\n\t- '.join(map(str, buckets))

# Print some information from first bucket
bucket = buckets[0]
print 'Bucket %s is located in %s with storage class %s' % (bucket, bucket.location,
                                                            bucket.storageClass)

# List the objects in the bucket
objects = bucket.list()
if not objects:
    print 'There are no objects, creating one'
    filename = '/tmp/my_file.txt'
    with bucket.open(filename, 'w') as f:
        f.write('this is a test file\n' * 100)
    objects = [gcs_client.Object(bucket.name, filename, credentials=credentials)]

if objects:
    print '\t', '\n\t'.join(map(lambda o: o.name + ' has %s bytes' % o.size, objects))
    # Read the contents from the first file
    with objects[0].open() as obj:
        print 'Contents of file %s are:\n' % obj.name, obj.read()
else:
    print 'There are no objects, nothing to do'

更多示例可以在文档的使用部分找到。

问题报告

如果您在gcs-client中发现问题,以下是报告问题的方法

  • 首选方法是向GitHub提交一个bug

    1. 前往项目的GitHub问题跟踪器

    2. 使用页面顶部的搜索字段搜索现有问题

    3. 提交一个新问题,包含关于问题的信息

    4. 感谢您帮助使gcs-client变得更好

  • 如果您没有GitHub账户并且不想创建一个,您可以给我发电子邮件。

历史

0.2.2 (2016-11-26)

  • 修复#1 - 媒体上传不工作

0.2.1 (2016-03-26)

  • 修复需求问题

0.2.0 (2015-11-25)

  • 添加使用Prefix对象的列表分隔符支持

  • 从google-api-python-client中移除依赖

  • 在AttributeError上返回描述性错误消息

0.1.4 (2015-11-16)

  • 没有更改,版本升级到pypi重新加载

0.1.3 (2015-11-16)

  • 读取对象将返回字节数据,而不是bytearray。

  • 读取对象的特定版本。

  • 可以在Bucket的open和Object init上指定chunksize。

  • 添加到bucket和project的exists方法。

  • 修复需要编码的文件名打开问题。

0.1.2 (2015-11-10)

  • 修复seek方法。

0.1.1 (2015-11-09)

  • 修复Pypi包。

0.1.0 (2015-11-09)

  • PyPI上的首次发布。

项目详情


下载文件

下载您平台上的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

gcs-client-0.2.2.tar.gz (40.3 kB 查看哈希值)

上传时间

构建分布

gcs_client-0.2.2-py2.py3-none-any.whl (37.4 kB 查看哈希值)

上传时间 Python 2 Python 3

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面