Skip to main content

Handle Amazon S3 interactions

Objects / files can be put into S3, retrieved from and deleted from S3. Also signed URLs can be generated to allow limited-time access to a particular object in an S3 bucket.

Requires Python 2.7 or above.

Available as Python package at http://pypi.python.org/pypi/pyawsbuckets [ pip install pyawsbuckets ] Source at https://github.com/mhenwood/pyawsbuckets

Usage

Initialise

Initiate the access object with your credentials:

from pyawsbuckets import AwsInterface
aws_interface = AwsInterface(amazon_access_key, amazon_secret_key)

PUT object

Put an object into an existing bucket at S3 (repeat: the bucket must ALREADY exist):

aws_interface.put(
    'https',
    'bucket999',
    'somefile.pdf',
    content)

Put an object into an existing bucket at S3, activating server-side encryption for that object:

aws_interface.put(
    'https',
    'bucket999',
    'somefile.pdf',
    content,
    server_side_encryption=True)

The put method also accepts an optional content_type keyword argument which should be a standard internet media type (e.g. “image/jpeg”)

GET object

Retrieve a given object from a given bucket:

object_contents = aws_interface(
    'https',
    'bucket999',
    'somefile.pdf')

DELETE object

Delete an object from S3:

aws_interface.delete('bucket999', 'somefile.pdf')

Expiring access URL

Get a signed URL which gives access to a private object, but only for (e.g.) 15 minutes. This is useful if you wish for users to be able to download private objects directly, but only for a brief window of time (to stop, for example, link sharing):

expiring_url = aws_interface.sign_object_request('https', 'bucket999', 'somefile.pdf', 15)

Using HTTPS

You can specify ‘https’ as the protocol for putting/getting files and for signing.

However you should bear in mind that given the way wildcard certificates work, the certificate presented by the S3 service will not match the requested hostname if your bucket name contains dots (periods).

This is because a certificate for “*.s3.amazon.com” will work nicely for hostnames like “foo.s3.amazon.com” and “foo-example-com.s3.example.com” but will NOT work for hostnames like “foo.bar.s3.amazon.com”. This is a feature of wildcard certificates and their jurisdiction, not of S3 or this library.

Because the bucket name gets translated into a hostname, this matters. It matters because your request will fail.

In short: avoid dots (periods) in bucket names if you plan to use https at all.

Known Limitations

Does not currently handle ‘307’ redirects from AWS - You will receive these for the first few hours of a bucket’s lifetime, until AWS’s DNS changes have propagated fully.

Metadata

Release files for pyawsbuckets 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyawsbuckets 1.2.0
File Size Uploaded
pyawsbuckets-1.2.0.tar.gz 5.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyawsbuckets 1.2.0
File Interpreter ABI Platform
pyawsbuckets-1.2.0-py2.7.egg Legacy Egg format - - Details

Total release size: 14.3 kB

Release files / pyawsbuckets-1.2.0.tar.gz

Download URL pyawsbuckets-1.2.0.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
56e0f1ca486bfcfa7066fdea03589bfc600f2f9ac7b4350370933a5fa16fd80b
BLAKE2b-256 checksum
How to use checksums
749a4a9edd42ce4f60a515b10da13dc9d327511add8ea9d2a4803daec39cbac1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pyawsbuckets-1.2.0-py2.7.egg

Download URL pyawsbuckets-1.2.0-py2.7.egg
Size 9.2 kB
Tags Egg
SHA-256 checksum
How to use checksums
361c872ee4140ea74882a3e4da41765336fbcd3cfcf2d2b5ba67c1fd5ff3e1a7
BLAKE2b-256 checksum
How to use checksums
48550ddb0623b1ed9362131a2f89ea0d0ead57cc851bf623ce84f3cc175202e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.0

2 release files

1.0.5

1 release file

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page