OpenS3 API

class openS3.utils.OpenS3(bucket, access_key, secret_key)[source]

A context manager for interfacing with S3.

content_type[source]

Return content_type of file. If file does not have a content_type, make a guess.

delete()[source]

Remove file from its S3 bucket.

exists()[source]

Return True if file exists in S3 bucket.

md5hash[source]

Return the MD5 hash string of the file content

open(object_key, mode='rb', content_type=None, acl='private', extra_request_headers=None)[source]

Configure OpenS3 object to write to or read from a specific S3 object.

Parameters:
  • object_key – A unique identifier for an object a bucket.
  • mode – The mode in which the S3 object is opened. See Modes below.
  • content_type – A standard MIME type describing the format of the contents.
  • acl – Name of a specific canned Access Control List to apply to the object.

Modes

mode Description
‘rb’ open for reading (default)
‘wb’ open for writing, truncating the file first
‘ab’ open for writing, appending to the end of the file if it exists

Access Control List (acl)

Valid values include:

  • private (default)
  • public-read
  • public-read-write
  • authenticated-read
  • bucket-owner-read
  • bucket-owner-full-control
read()[source]

Return a bytes object with the contents of the remote S3 object.

Rtype bytes:
size[source]

Return the size of the buffer, in bytes.

url[source]

Return URL of resource

write(content)[source]

Write content to file in S3.

Parameters:content
exception openS3.utils.S3IOError[source]

Generic exception class for S3 communication errors.

openS3.utils.b64_string(byte_string)[source]

Return an base64 encoded byte string as an ENCODING decoded string

openS3.utils.get_valid_filename(string_to_clean)[source]

Returns the given string converted to a string that can be used for a clean filename. Specifically, leading and trailing spaces are removed; other spaces are converted to underscores; and anything that is not a unicode alphanumeric, dash, underscore, or dot, is removed.

>>> get_valid_filename("john's portrait in 2004.jpg")
'johns_portrait_in_2004.jpg'
openS3.utils.strpawstime(timestamp)[source]

Return datetime from parsed AWS header timestamp string. AWS Datetime Format: Wed, 28 Oct 2009 22:32:00 GMT

openS3.utils.validate_values(validation_func, dic)[source]

Validate each value in dic by passing it through func. Raise a ValueError if validation_func does not return True.

Previous topic

Changelog

This Page