drugforge.data.services.aws.s3.S3

class drugforge.data.services.aws.s3.S3(session: Session, bucket: str, prefix: str | None = None, endpoint_url=None)[source]

Bases: object

Interface for AWS S3.

__init__(session: Session, bucket: str, prefix: str | None = None, endpoint_url=None)[source]

Create an interface to AWS S3.

Parameters:
  • session – A boto3.Session object, already parameterized with credentials, region, etc.

  • bucket – The name of the S3 bucket to target.

  • prefix – The prefix to use for referencing objects in the bucket; functions as a working sub-folder/directory.

  • endpoint_url – The S3 endpoint to use; used for testing, generally not needed.

Methods

__init__(session, bucket[, prefix, endpoint_url])

Create an interface to AWS S3.

from_settings(settings)

Create an interface to AWS S3 from a Settings object.

initialize()

Initialize bucket.

pull_file()

push_dir(path[, location])

Push a directory at the local filesystem path to an object location in this S3 Bucket.

push_file(path[, location, content_type])

Push a file at the local filesystem path to an object location in this S3 Bucket.

reset()

Delete all objects, including bucket itself.

to_uri(location)

Convert a location in the S3 bucket to a URI.

classmethod from_settings(settings)[source]

Create an interface to AWS S3 from a Settings object.

Parameters:
  • settings – A S3Settings object.

  • prefix – The prefix to use for referencing objects in the bucket; functions as a working sub-folder/directory.

Returns:

S3 interface object.

Return type:

S3

initialize()[source]

Initialize bucket.

Creates bucket if it does not exist.

push_dir(path: PathLike, location: PathLike = None)[source]

Push a directory at the local filesystem path to an object location in this S3 Bucket.

location is relative to the prefix set for use of this bucket; e.g. if location='foo' and self.prefix == 'baz', then the object will be located at baz/foo in the bucket.

Parameters:
  • path – Path to directory on local filesystem to push.

  • location – Location in the S3 bucket to place object relative to self.prefix; should not contain a leading /.

push_file(path: PathLike, location: PathLike = None, content_type: str = None)[source]

Push a file at the local filesystem path to an object location in this S3 Bucket.

location is relative to the prefix set for use of this bucket; e.g. if location='foo/bar.html' and self.prefix == 'baz', then the object will be located at baz/foo/bar.html in the bucket.

Parameters:
  • path – Path to file on local filesystem to push.

  • location – Location in the S3 bucket to place object relative to self.prefix; should not contain a leading /.

  • content_type – Media type of the file being pushed. This will impact how the file is handled by a browser upon URL access, e.g. for html you want rendered on access, use 'text/html'.

reset()[source]

Delete all objects, including bucket itself.

Inverse operation of initialize.

to_uri(location: PathLike)[source]

Convert a location in the S3 bucket to a URI.

Parameters:

location – Location in the S3 bucket to convert to a URI.

Returns:

URI for the object in the S3 bucket.

Return type:

str