Package: s3path
S3PathS3Path provide a Python convenient File-System/Path like interface for AWS S3 Service using boto3 S3 resource as a driver.Like pathlib, but for S3 BucketsAWS S3 is among the most popular cloud storage solutions. It’s object storage, is built to store and retrieve various amounts of data from anywhere.Currently, Python developers use Boto3 as the default API to connect / put / get / list / delete files from S3.S3Path blends Boto3’s ease of use and the familiarity of pathlib api.Install:From PyPI:$pipinstalls3pathFrom Conda:$condainstall-cconda-forges3pathBasic use:The following example assumes an s3 bucket setup as specified bellow:$awss3lss3://pypi-proxy/2018-04-2422:59:59186requests/index.html2018-04-2422:59:57485015requests/requests-2.9.1.tar.gz2018-04-2422:35:0189112boto3/boto3-1.4.1.tar.gz2018-04-2422:35:02180boto3/index.html2018-04-2422:35:193308919botocore/botocore-1.4.93.tar.gz2018-04-2422:35:36188botocore/index.htmlImporting the main class:>>>froms3pathimportS3PathListing “subdirectories” - s3 keys can be split like file-system with a/in s3path we:>>>bucket_path=S3Path('/pypi-proxy/')>>>[pathforpathinbucket_path.iterdir()ifpath.is_dir()][S3Path('/pypi-proxy/requests/'),S3Path('/pypi-proxy/boto3/'),S3Path('/pypi-proxy/botocore/')]Listing html source files in this “directory” tree:>>>bucket_path=S3Path('/pypi-proxy/')>>>list(bucket_path.glob('**/*.html'))[S3Path('/pypi-proxy/requests/index.html'),S3Path('/pypi-proxy/boto3/index.html'),S3Path('/pypi-proxy/botocore/index.html')]Navigating inside a “directory” tree:>>>bucket_path=S3Path('/pypi-proxy/')>>>boto3_package_path=bucket_path/'boto3'/'boto3-1.4.1.tar.gz'>>>boto3_package_pathS3Path('/pypi-proxy/boto3/boto3-1.4.1.tar.gz')Querying path properties:>>>boto3_package_path=S3Path('/pypi-proxy/boto3/boto3-1.4.1.tar.gz')>>>boto3_package_path.exists()True>>>boto3_package_path.is_dir()False>>>boto3_package_path.is_file()TrueOpening a “file” (s3 key):>>>botocore_index_path=S3Path('/pypi-proxy/botocore/index.html')>>>withbotocore_index_path.open()asf:>>>print(f.read())"""
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Package Index</title>
</head>
<body>
    <a href="botocore-1.4.93.tar.gz">botocore-1.4.93.tar.gz</a><br>
</body>
</html>
"""Or Simply reading:>>>botocore_index_path=S3Path('/pypi-proxy/botocore/index.html')>>>botocore_index_path.read_text()"""
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Package Index</title>
</head>
<body>
    <a href="botocore-1.4.93.tar.gz">botocore-1.4.93.tar.gz</a><br>
</body>
</html>
"""Versioned S3 Objects:s3path supports versioned objects for S3 buckets that have versioning enabled.VersionedS3Pathis a subclass ofS3Paththat supports all of its features. The main difference is an additional requiredversion_idkeyword parameter in each of its constructor methods.>>>froms3pathimportVersionedS3Path>>>bucket,key,version_id='my-bucket','my-key','my-version-id'>>>VersionedS3Path(f'/{bucket}/{key}',version_id=version_id)VersionedS3Path('/my-bucket/my-key',version_id='my-version-id')>>>VersionedS3Path.from_uri(f's3://{bucket}/{key}',version_id=version_id)VersionedS3Path('/my-bucket/my-key',version_id='my-version-id')>>>VersionedS3Path.from_bucket_key(bucket=bucket,key=key,version_id=version_id)VersionedS3Path('/my-bucket/my-key',version_id='my-version-id')New in version 0.5.0Requirements:Python >= 3.4boto3smart-openFurther Documentation:Advanced S3Path configuration(S3 parameters, S3-compatible storage, etc.)Abstract pathlib interfaceimplemented by S3PathBoto3 vs S3Path usage examples