没有项目描述
s3path的Python项目详细描述
S3路径
s3 path使用boto3 s3资源作为驱动程序,为awss3服务提供了一个类似python的文件系统/路径接口。
类似于pathlib,但对于s3 bucket
aws s3是最流行的云存储解决方案之一。它的对象存储,是为了从任何地方存储和检索各种数量的数据而构建的。
目前,python开发人员使用boto3作为默认api,从s3连接/放置/获取/列出/删除文件。
S3Path融合了Boto3的易用性和Pathlib API的熟悉性。
安装:
$ pip install s3path
基本用途:
以下示例假设S3 bucket设置如下所示:
$ aws s3 ls s3://pypi-proxy/ 2018-04-24 22:59:59 186 requests/index.html 2018-04-24 22:59:57 485015 requests/requests-2.9.1.tar.gz 2018-04-24 22:35:01 89112 boto3/boto3-1.4.1.tar.gz 2018-04-24 22:35:02 180 boto3/index.html 2018-04-24 22:35:19 3308919 botocore/botocore-1.4.93.tar.gz 2018-04-24 22:35:36 188 botocore/index.html
导入主类:
>>>froms3pathimportS3Path
列出“子目录”-s3键可以像文件系统一样拆分,在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/')]
在此“目录”树中列出HTML源文件:
>>>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')]
在“目录”树中导航:
>>>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')
查询路径属性:
>>>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()True
打开“文件”(S3键):
>>>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> """
或者只是阅读:
>>>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> """
要求:
- python=3.4
- BOTO3
所有接口的pathlib样式文档interface_docs。
对于s3path与boto3比较boto3_comparison。
对于高级功能(配置/s3参数)boto3_advance。