谷歌云存储python客户端
gcs-client的Python项目详细描述
地面军事系统客户端
谷歌云存储python客户端
- apache 2.0许可证
- 文档:https://gcs-client.readthedocs.org。
其思想是创建一个具有类似于Google’s appengine-gcs-client的功能的客户机,但其目的是用于从外部运行的应用程序 谷歌的appengine。
云存储文档可以在Google
功能
目前只提供基本功能:
- 创建存储桶
- 删除存储桶
- 列出项目中的存储桶
- 获取项目的默认存储桶
- 获取bucket属性
- 列出bucket中的对象
- 获取对象属性
- 删除对象
- 读取对象内容
- 编写对象
- 具有截断指数退避的可配置重试
安装
要安装,只需运行:
$ pip install --upgrade gcs-client
使用示例
要在项目中使用gcs客户端,您需要具有访问预期google云存储的凭据。
凭据在项目的api管理器的Credentials section中的Google Developers Console中生成。推荐的凭据文件是json。
一旦您有了凭据,就可以开始使用gcs_客户端访问您的项目:
importgcs_clientcredentials=gcs_client.Credentials('private_key.json')project=gcs_client.Project('project_name',credentials)# Print buckets in the projectbuckets=project.list()print'Buckets:\n\t-','\n\t- '.join(map(str,buckets))# Print some information from first bucketbucket=buckets[0]print'Bucket %s is located in %s with storage class %s'%(bucket,bucket.location,bucket.storageClass)# List the objects in the bucketobjects=bucket.list()ifnotobjects:print'There are no objects, creating one'filename='/tmp/my_file.txt'withbucket.open(filename,'w')asf:f.write('this is a test file\n'*100)objects=[gcs_client.Object(bucket.name,filename,credentials=credentials)]ifobjects:print'\t','\n\t'.join(map(lambdao:o.name+' has %s bytes'%o.size,objects))# Read the contents from the first filewithobjects[0].open()asobj:print'Contents of file %s are:\n'%obj.name,obj.read()else:print'There are no objects, nothing to do'
更多的例子可以在文档中的usage部分找到。
报告问题
如果您发现GCS客户端有问题,请使用以下方法报告问题:
- 首选方法是在github上提交一个bug:
- 转到项目的issue tracker on GitHub
- 用有关问题的信息提交新问题
- 感谢您帮助改进GCS客户端
使用页面顶部的搜索字段< /LI>搜索现有问题 - 如果您没有github帐户,并且不希望创建一个帐户,您可以 给我发邮件。
历史记录
0.2.2(2016-11-26)
- 修复1-媒体上载无法工作
0.2.1(2016-03-26)
- 解决需求问题
0.2.0(2015-11-25)
- 在使用前缀对象的列表中添加对分隔符的支持
- 从google api python客户端删除依赖项
- 在attributeerror上返回描述性错误消息
0.1.4(2015-11-16)
- 无更改,在pypi中重新加载版本bump
0.1.3(2015-11-16)
- 读取对象将返回字节形式的数据,而不是字节数组。
- 读取对象的特定版本。
- 可以在bucket的open和object init上指定chunksize。
- 修复打开需要编码的文件的问题。
0.1.2(2015-11-10)
- 固定搜索方法。
0.1.1(2015-11-09)
- 修复pypi包。
0.1.0(2015-11-09)
- pypi上的第一个版本。