一个与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如何使用JNA创建同一库的多个实例?   java在将Graphql查询作为JSON字符串传递时收到意外的令牌错误   OAuth2 oltu的java问题   java桌面应用程序使用的好的嵌入式数据库是什么?   java Firebase数据库高级查询选项   java正在使磁盘上的EhCache元素过期   java 安卓还原处于backstack中的片段的实例状态   XMemcached中的java异步集   java TimescaleDB是否使用与Postgresql完全相同的JDBC驱动程序?   java从网站c读取信息#   检查java Android中的字符串是否只包含数字和空格   c#如何向web服务发送特殊字符?   grails无法调用需要java的方法。lang.类参数?   java我在组合框中调用的方法不会运行所有代码,它只运行部分代码   java发送带有标头的HTTP GET请求