Skip to main content

A simple library for interacting with Amazon S3.

Project description

PyPI version Code style: black Python 3.6+ supported

bucketstore is a very simple Amazon S3 client, written in Python. It aims to be much more straight-forward to use than boto3, and specializes only in Amazon S3, ignoring the rest of the AWS ecosystem.

Features

  • Treats S3 Buckets as Key/Value stores.
  • Automatic support for AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_DEFAULT_REGION environment variables.
  • Easily make keys (or entire buckets) publically accessable.
  • Easily get the public URL for a given key.
  • Generates temporary URLs for a given key.
  • Use S3 in a pythonic way!

Usage

Installation

pip install bucketstore

Get (or create) a bucket, easily:

import bucketstore

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

Treat the bucket like a key/value store:

>>> 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']
{}

Interact with S3 keys:

>>> 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

Other methods include bucketstore.login(access_key_id, secret_access_key), bucketstore.list(), and bucketstore.get(bucket_name, create=False).

Tests

Tests are run through Tox.

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

✨🍰✨

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bucketstore-0.2.2.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

bucketstore-0.2.2-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file bucketstore-0.2.2.tar.gz.

File metadata

  • Download URL: bucketstore-0.2.2.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for bucketstore-0.2.2.tar.gz
Algorithm Hash digest
SHA256 4d87cbe33edb0de5a5c0f79d6ed2c6537539571482d6aeed3d819c7d250fb403
MD5 ca0597778b981febeacfeb8ea3c96b79
BLAKE2b-256 efae9e4c0159d77512ed35957db0c6d290c3aa59671c2c358b181d1191c788a2

See more details on using hashes here.

File details

Details for the file bucketstore-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: bucketstore-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for bucketstore-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 29ecd4ab369acecd0fe53934e11396ff58e30c42962318a15976f0242ff34f87
MD5 50f3be1a067461b293c57f7e7d07e37d
BLAKE2b-256 d42c3dc9e48d9c0dfeed1c5557abdd0cc68b888a6df007cccba879f048b5214f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page