attribute#
S3Path property methods.
- class s3pathlib.core.attribute.AttributeAPIMixin[source]#
A mixin class that implements the property methods.
- property parent: S3Path | None#
Return the parent s3 directory.
- if current object is on s3 bucket root directory, it returns bucket
root directory
it is always a directory (
s3path.is_dir() is True
)if it is already s3 bucket root directory, it returns
None
Examples:
>>> S3Path("my-bucket", "my-folder", "my-file.json").parent.uri s3://my-bucket/my-folder/ >>> S3Path("my-bucket", "my-folder", "my-subfolder/").parent.uri s3://my-bucket/my-folder/ >>> S3Path("my-bucket", "my-folder").parent.uri s3://my-bucket/ >>> S3Path("my-bucket", "my-file.json").parent.uri s3://my-bucket/
New in version 1.0.1.
- property parents: List[S3Path]#
An immutable sequence providing access to the logical ancestors of the path.
Examples:
>>> S3Path("my-bucket", "my-folder", "my-file.json").parents s3://my-bucket/my-folder/
New in version 1.0.6.
- is_parent_of(other: S3Path) bool [source]#
Test if it is the parent directory or grand-grand-… parent directory of another one.
Examples:
# is parent >>> S3Path("bucket").is_parent_of(S3Path("bucket/folder/")) True # is grand parent >>> S3Path("bucket").is_parent_of(S3Path("bucket/folder/file.txt")) True # the root bucket's parent is itself >>> S3Path("bucket").is_parent_of(S3Path("bucket")) True # the 'self' has to be a directory >>> S3Path("bucket/a").is_parent_of(S3Path("bucket/a/b/c")) TypeError: S3Path('s3://bucket/a') is not a valid directory! # the 'self' and 'other' has to be concrete S3Path >>> S3Path().is_parent_of(S3Path()) TypeError: both S3Path(), S3Path() has to be a concrete S3Path!
New in version 1.0.2.
- is_prefix_of(other: S3Path) bool [source]#
Test if it is a prefix of another one.
Example:
>>> S3Path("bucket/folder/").is_prefix_of(S3Path("bucket/folder/file.txt")) True >>> S3Path("bucket/folder/").is_prefix_of(S3Path("bucket/folder/")) True
New in version 1.0.2.
- basename[source]#
The file name with extension, or the last folder name if it is a directory. If not available, it returns None. For example it doesn’t make sence for s3 bucket.
Logically: dirname + basename = abspath
Example:
# s3 object >>> S3Path("bucket", "folder", "file.txt").basename 'file.txt' # s3 directory >>> S3Path("bucket", "folder/").basename 'folder' # s3 bucket >>> S3Path("bucket").basename None # void path >>> S3Path().basename '' # relative path >>> S3Path.make_relpath("folder", "file.txt").basename None
New in version 1.0.1.
- dirname[source]#
The basename of it’s parent directory.
Example:
>>> S3Path("bucket", "folder", "file.txt").dirname 'folder' # root dir name is '' >>> S3Path("bucket", "folder").dirname ''
New in version 1.0.1.
- fname[source]#
The final path component, minus its last suffix (file extension). Only if it is not a directory.
Example:
>>> S3Path("bucket", "folder", "file.txt").fname 'file'
New in version 1.0.1.
- ext[source]#
The final component’s last suffix, if any. Usually it is the file extension. Only if it is not a directory.
Example:
>>> S3Path("bucket", "folder", "file.txt").fname '.txt'
New in version 1.0.1.
- abspath[source]#
The Unix styled absolute path from the bucket. You can think of the bucket as a root drive.
Example:
# s3 object >>> S3Path("bucket", "folder", "file.txt").abspath '/folder/file.txt' # s3 directory >>> S3Path("bucket", "folder/").abspath '/folder/' # s3 bucket >>> S3Path("bucket").abspath '/' # void path >>> S3Path().abspath TypeError: relative path doesn't have absolute path! # relative path >>> S3Path.make_relpath("folder", "file.txt").abspath TypeError: relative path doesn't have absolute path!
New in version 1.0.1.
- dirpath[source]#
The Unix styled absolute path from the bucket of the parent directory.
Example:
# s3 object >>> S3Path("bucket", "folder", "file.txt").dirpath '/folder/' # s3 directory >>> S3Path("bucket", "folder/").dirpath '/' # s3 bucket >>> S3Path("bucket").dirpath '/' # void path >>> S3Path().dirpath TypeError: relative path doesn't have absolute path! # relative path >>> S3Path.make_relpath("folder", "file.txt").dirpath TypeError: relative path doesn't have absolute path!
New in version 1.0.2.