一个与amazon s3交互的简单库。
bucketstore的Python项目详细描述
bucketstore是一个非常简单的amazon s3客户端,用python编写。它 目的是比Boto3更直接的使用,并且专门 仅在amazon s3中,忽略了aws生态系统的其余部分。
功能
- 将s3存储桶视为键/值存储。
- 自动支持AWS_ACCESS_KEY_ID、AWS_SECRET_ACCESS_KEY和AWS_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