一个用于与Amazon S3交互的简单库。
项目描述
bucketstore是一个用Python编写的非常简单的Amazon S3客户端。它的目标是比boto3更容易使用,并且仅专注于Amazon S3,忽略AWS生态系统的其余部分。
特性
- 将S3存储桶视为键/值存储。
- 自动支持
AWS_ACCESS_KEY_ID
、AWS_SECRET_ACCESS_KEY
和AWS_DEFAULT_REGION
环境变量。 - 轻松使键(或整个存储桶)公开访问。
- 轻松获取给定键的公开URL。
- 为给定键生成临时URL。
- 以Python方式使用S3!
用法
安装
pip install bucketstore
轻松获取(或创建)一个存储桶
import bucketstore
# Create the bucket if it doesn't exist.
bucket = bucketstore.get('bucketstore-playground', create=True)
将存储桶视为键/值存储
>>> 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' in bucket
True
# delete keys in the bucket
>>> del bucket['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 a content type
>>> foo = bucket.key('foo.html')
>>> foo.set('<h1>bar</h1>', content_type='text/html')
# upload to key
>>> bucket.key('test.py').upload('/tmp/test.py')
# or upload with a file-like object! (make sure it's open in binary mode)
>>> with open('/tmp/test.py', 'rb') as file:
>>> bucket.key('test.py').upload(file)
# download to file
>>> bucket.key('test.py').download('/tmp/test.py')
# or download to a file-like object! (make sure it's open in binary mode)
>>> with open('/tmp/test.py', 'wb') as file:
>>> bucket.key('test.py').download(file)
# size of key
>>> bucket.key('test.py').size()
>>> len(bucket.key('test.py'))
15
其他方法包括 bucketstore.login(access_key_id, secret_access_key)
、bucketstore.list()
和 bucketstore.get(bucket_name, create=False)
。
测试
测试通过 Tox 运行。
✨🍰✨
项目详情
下载文件
下载您平台对应的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。
源分布
bucketstore-0.3.0.tar.gz (5.9 kB 查看哈希)
构建分布
bucketstore-0.3.0-py3-none-any.whl (6.1 kB 查看哈希)
关闭
bucketstore-0.3.0.tar.gz 的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 9136670f9a828cd290224fe702bd9eab0a58198643e59a8f4f476b12ee3bb117 |
|
MD5 | 1e532f168969c1f52b35c723560abe0d |
|
BLAKE2b-256 | b955695a5407c8c8b347924c4e26119fee73ce0e7e19b664ab723ba1153b9b7f |
关闭
bucketstore-0.3.0-py3-none-any.whl 的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 41029a640c80bcafc4949b29a95ce185e4e77829eef41574d3a9230747843be8 |
|
MD5 | 2a43a0ea4166cc576c909a80ac236ae5 |
|
BLAKE2b-256 | 4f801e558ebf6d4674ffb6f047fdfaee8b10befece09aa295eeab0a666f4ca61 |