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:
objectInterface 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 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:
- 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'andself.prefix == 'baz', then the object will be located atbaz/fooin 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'andself.prefix == 'baz', then the object will be located atbaz/foo/bar.htmlin 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
htmlyou want rendered on access, use'text/html'.