一个与amazon s3交互的简单库。

bucketstore的Python项目详细描述


https://travis-ci.org/jpetrucciani/bucketstore.svg?branch=masterPyPI versionCode style: blackPython 3.5+ supported

bucketstore是一个非常简单的amazon s3客户端,用python编写。它 目的是比Boto3更直接的使用,并且专门 仅在amazon s3中,忽略了aws生态系统的其余部分。

功能

  • 将s3存储桶视为键/值存储。
  • 自动支持AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_DEFAULT_REGION环境变量。
  • 很容易使密钥(或整个桶)公开访问。
  • 轻松获取给定密钥的公共url。
  • 为给定密钥生成临时URL。
  • 以Python的方式使用s3!

用法

安装

$ pip install bucketstore

获取(或创建)一个bucket,很容易:

importbucketstore# Create the bucket if it doesn't exist.bucket=bucketstore.get('bucketstore-playground',create=True)

把bucket当作键/值存储:

>>> bucket<S3Bucket name='bucketstore-playground'>

# get/set using array syntax
>>> bucket['foo']='bar'>>> bucket['foo']bar

# get/set using methods
>>> bucket.set('foo2','bar2')>>> bucket.get('foo2')bar2

# list keys
>>> bucket.list()[u'foo', u'foo2']

# all keys
>>> bucket.all()[<S3Key name=u'foo' bucket='bucketstore-playground'>, <S3Key name=u'foo2' bucket='bucketstore-playground'>]

# check if a key exists in the bucket
>>> 'foo'inbucketTrue

# delete keys in the bucket
>>> delbucket['foo2']{}

与S3键交互:

>>> bucket.key('foo')<S3Key bucket='bucketstore-playground' name=u'foo'>

>>> foo=_>>> foo.set('new value')
# Generate a temporary share URL.
>>> foo.temp_url(duration=1200)u'https://bucketstore-playground.s3.amazonaws.com/foo?AWSAccessKeyId=AKIAI2RVFNXIW7WS66QQ&Expires=1485493909&Signature=L3gD9avwQZQO1i11dIJXUiZ7Nx8%3D'

# Make key publically accessable.
>>> foo.make_public()>>> foo.url'https://s3.amazonaws.com/bucketstore-playground/foo'

# Get / set metadata for key.
>>> foo.meta={'foo':'bar'}>>> foo.meta{'foo': 'bar}

# Rename key to 'foo3'.
>>> foo.rename('foo3')
# Delete the key.
>>> foo.delete()
# Create a key with metadata at the same time.
>>> foo=bucket.key('foo.html')>>> foo.set('<h1>bar</h1>',{'content_type':'text/html'})

其他方法包括bucketstore.login(access_key_id, secret_access_key)bucketstore.list()bucketstore.get(bucket_name, create=False)

测试

测试通过Tox运行。

# Run tests against all environments.
$ tox
# Run against a specific version.
$ tox -e py35
# Run with pytest arguments.
$ tox -- --pdb

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java线程执行器服务   aspose如何通过java获得单词bookmark之前的所有文本内容?   一对一映射的java Hibernate合并问题   java SOAP XSD根元素问题   java如何保护我的Spring启动API   java使用GeoJson向google地图添加标记   java安卓:在SQLite中没有这样的列   java STS 2.8.0 StartExplorer/Legacy插件安装问题   java如何以编程方式获取AppBar高度?   在Java中将BigDecimal添加到BigDecimal   java不支持ntdll。dll是windows xp和windows vista的标准配置吗?   内容类型为application/xwwwformurlencoded的java Http Put请求在Spring中不起作用   java在数组中计算工资并返回答案   java数字/货币格式   elasticsearch java api中的弹性搜索查询