base#
The base constructor of S3Path object.
- class s3pathlib.core.base.BaseS3Path(*args: str | S3Path)[source]#
Similar to
pathlib.Path
. An objective oriented programming interface for AWS S3 object or logical directory.You can use this class in different way.
- pure s3 object / directory path manipulation without actually
talking to AWS API.
- get metadata of an object, count objects, get statistics information
of a directory
- enhanced s3 API that do:
upload_file
, upload_dir
,copy
a file or directory,move
a file or directory,delete
a file or directory,iter_objects
from a prefix.
- enhanced s3 API that do:
Constructor
The
S3Path
itself is a constructor. It takesstr
and other relativeS3Path
as arguments.The first argument defines the S3 bucket
The rest of arguments defines the path parts of the S3 key
- The final argument defines the type whether is a file (object) or
a directory
First let’s create a S3 object path from string:
# first argument becomes the bucket >>> s3path = S3Path("bucket", "folder", "file.txt") # print S3Path object gives you info in S3 URI format >>> s3path S3Path('s3://bucket/folder/file.txt') # If the last argument has a trailing slash ("/"), it indicates that # it refers to a directory. Otherwise, it is assumed to be a file. >>> s3path.is_file() True >>> s3path.is_dir() False # "/" separator will be automatically handled >>> S3Path("bucket", "folder/file.txt") S3Path('s3://bucket/folder/file.txt') >>> S3Path("bucket/folder/file.txt") S3Path('s3://bucket/folder/file.txt')
Then let’s create a S3 directory path:
>>> s3path= S3Path("bucket/folder/") >>> s3path S3Path('s3://bucket/folder/') # last argument defines that it is a directory >>> s3path.is_dir() True >>> s3path.is_file() False
You can also create it from S3 URI or ARN:
>>> S3Path("s3://bucket/folder/file.txt") S3Path('s3://bucket/folder/file.txt') >>> S3Path("arn:aws:s3:::bucket/folder/file.txt"), S3Path('s3://bucket/folder/file.txt')
New in version 1.0.1.
Changed in version 2.0.1: You can create S3Path from s3 uri or arn directly.