mutate#

S3Path object mutation implementation.

class s3pathlib.core.mutate.MutateAPIMixin[source]#

A mixin class that implements the S3Path object mutation.

copy() S3Path[source]#

Create a copy of S3Path object that logically equals to this one, but is actually different identity in memory. Also, the cache data are cleared.

Example:

>>> p1 = S3Path("bucket", "folder", "file.txt")
>>> p2 = p1.copy()
>>> p1 == p2
True
>>> p1 is p2
False

New in version 1.0.1.

change(new_bucket: str = None, new_abspath: str = None, new_dirpath: str = None, new_dirname: str = None, new_basename: str = None, new_fname: str = None, new_ext: str = None) S3Path[source]#

Create a new S3Path by replacing part of the attributes. If no argument is given, it behaves like copy().

Example:

>>> s3path = S3Path("bucket", "folder", "file.txt")
>>> s3path.change(new_bucket="new_bucket")
S3Path('s3://new_bucket/folder/file.txt')
>>> s3path = S3Path("bucket", "folder", "file.txt")
>>> s3path.change(new_basename="data.json")
S3Path('s3://bucket/folder/data.json')
>>> s3path = S3Path("bucket", "folder", "file.txt")
>>> s3path.change(new_fname="log")
S3Path('s3://bucket/folder/log.txt')
Parameters:
  • new_bucket – The new bucket name

  • new_abspath

  • new_dirpath

  • new_dirname

  • new_basename

  • new_fname

  • new_ext

New in version 1.0.2.

to_dir() S3Path[source]#

Convert the S3Path to a directory. If the S3Path is a file, then append a “/” at the end. If the S3Path is already a directory, then do nothing.

Example:

>>> S3Path.from_s3_uri("s3://bucket/folder").to_dir()
S3Path('s3://bucket/folder/')
to_file() S3Path[source]#

Convert the S3Path to a file. If the S3Path is a directory, then strip out the last “/”. If the S3Path is already a file, then do nothing.

Example:

>>> S3Path.from_s3_uri("s3://bucket/file/").to_dir()
S3Path('s3://bucket/file/')