Use PureS3Path for S3 path manipulation
masterPureS3Path is a subclass of PurePath designed for AWS S3 semantics. It allows for path manipulation without performing actual I/O operations.
Key Differences from PurePosixPath:
- S3 does not support symbolic links, so double dots (
'..') are resolved by collapsing the path:PureS3Path('foo/../bar')becomesPureS3Path('bar'). - All methods will raise
ValueErrorif the path is not absolute.
Common Methods:
as_uri(): Returns the path as ans3://URI.from_uri(uri): Creates aPureS3Pathfrom an S3 URI.from_bucket_key(bucket, key): Creates aPureS3Pathfrom a bucket and key pair..bucket: Property returning the bucket name string..key: Property returning the key name string.
from s3path import PureS3Path
# Creation
p = PureS3Path('/pypi-proxy/boto3/index.html')
# Properties
print(p.bucket) # 'pypi-proxy'
print(p.key) # 'boto3/index.html'
# URI conversion
print(p.as_uri()) # 's3://pypi-proxy/boto3/index.html'
# From URI
p2 = PureS3Path.from_uri('s3://pypi-proxy/boto3/index.html')
# From Bucket/Key
p3 = PureS3Path.from_bucket_key('pypi-proxy', 'boto3/index.html')