OpenS3 API

class openS3.ctx_manager.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.

listdir()[source]

Return a 2-tuple of directories and files in object_key.

Return type:tuple
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

Previous topic

openS3

Next topic

Testing

This Page