未提供项目说明
cloudpathlib的Python项目详细描述
Our goal is to be the meringue of file management libraries: the subtle sweetness of
pathlib
working in harmony with the ethereal lightness of the cloud.
为不同的云存储服务实现(几乎全部)uri的pathlib.Path
方法的库。在
withCloudPath("s3://bucket/filename.txt").open("w+")asf:f.write("Send my changes to the cloud!")
为什么使用cloudpathlib?在
- knowner:如果您知道如何与
Path
交互,那么您就知道如何与{}交互。实现了所有与云相关的 Path
方法。在 - 支持的云:实现了aws3和azureblob存储。Google云存储和FTP正在开发中。在
- Extensible:基类通常完成大部分工作,因此实现两个小类
MyPath
和{}是添加对新云存储服务的支持所需的全部内容。在 - Read/write支持:读取就可以了。使用
write_text
、write_bytes
或.open('w')
方法都可以将更改上载到云存储,而不需要作为开发人员进行任何额外的文件管理。在 - 无缝缓存:文件仅在必要时在本地下载。您还可以轻松地传递持久缓存文件夹,以便跨进程和会话重新下载所需的内容。在
- Tested:全面的测试套件和代码覆盖率。在
安装
cloudpathlib
依赖于云服务的sdk(例如,boto3
,azure-storage-blob
)与各自的存储服务通信。如果您尝试为没有安装依赖项的云服务使用云路径,cloudpathlib
将出错并告诉您需要安装什么。在
要在安装cloudpathlib
时安装云服务的SDK依赖项,需要使用pip的"extras"规范来指定它。例如:
当前支持的云存储服务有:azure
,s3
。您还可以使用all
安装所有可用服务的依赖项。在
如果您不指定任何附加功能或单独安装任何云SDK,则只能使用基类进行开发,以滚动您自己的云路径类。在
康达
cloudpathlib
也可以使用conda forge的conda
。请注意,要安装必要的云服务SDK依赖项,您应该在包名称中包含适当的后缀。例如:
conda install cloudpathlib-s3 -c conda-forge
如果不使用后缀,则只有基类可用。有关所有安装选项,请参阅conda-forge/cloudpathlib-feedstock。在
开发版本
您可以从GitHub获取最新的开发版本:
pip install https://github.com/drivendataorg/cloudpathlib.git#egg=cloudpathlib[all]
注意,您同样需要指定云服务依赖项,例如上面示例命令中的all
。在
快速使用
下面是一个示例来了解使用该包的要点。默认情况下,cloudpathlib
使用每个云服务SDK支持的环境变量进行身份验证。有关更多详细信息和高级身份验证选项,请参阅"Authentication"文档。在
fromcloudpathlibimportCloudPath# dispatches to S3Path based on prefixroot_dir=CloudPath("s3://drivendata-public-assets/")root_dir#> S3Path('s3://drivendata-public-assets/')# there's only one file, but globbing works in nested folderforfinroot_dir.glob('**/*.txt'):text_data=f.read_text()print(f)print(text_data)#> s3://drivendata-public-assets/odsc-west-2019/DATA_DICTIONARY.txt#> Eviction Lab Data Dictionary#>#> Additional information in our FAQ evictionlab.org/help-faq/#> Full methodology evictionlab.org/methods/#>#> ... (additional text output truncated)# use / to join paths (and, in this case, create a new file)new_file_copy=root_dir/"nested_dir/copy_file.txt"new_file_copy#> S3Path('s3://drivendata-public-assets/nested_dir/copy_file.txt')# show things work and the file does not exist yetnew_file_copy.exists()#> False# writing text data to the new file in the cloudnew_file_copy.write_text(text_data)#> 6933# file now listedlist(root_dir.glob('**/*.txt'))#> [S3Path('s3://drivendata-public-assets/nested_dir/copy_file.txt'),#> S3Path('s3://drivendata-public-assets/odsc-west-2019/DATA_DICTIONARY.txt')]# but, we can remove itnew_file_copy.unlink()# no longer therelist(root_dir.glob('**/*.txt'))#> [S3Path('s3://drivendata-public-assets/odsc-west-2019/DATA_DICTIONARY.txt')]
支持的方法和属性
除了那些在云上下文中没有意义的方法和属性外,pathlib.Path
中的大多数方法和属性都受支持。还有一些附加的方法或属性与特定的云服务或云路径相关。在
Methods + properties | ^{ | ^{ |
---|---|---|
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ❌ | ❌ |
^{ | ❌ | ❌ |
^{ | ❌ | ❌ |
^{ | ❌ | ❌ |
^{ | ❌ | ❌ |
^{ | ❌ | ❌ |
^{ | ❌ | ❌ |
^{ | ❌ | ❌ |
^{ | ❌ | ❌ |
^{ | ❌ | ❌ |
^{ | ❌ | ❌ |
^{ | ❌ | ❌ |
^{ | ❌ | ❌ |
^{ | ❌ | ❌ |
^{ | ❌ | ❌ |
^{ | ❌ | ❌ |
^{ | ❌ | ❌ |
^{ | ❌ | ❌ |
^{ | ❌ | ❌ |
^{ | ❌ | ❌ |
^{ | ❌ | ❌ |
^{ | ❌ | ❌ |
^{ | ❌ | ❌ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ✅ |
^{ | ✅ | ❌ |
^{ | ❌ | ✅ |
^{ | ✅ | ❌ |
^{ | ❌ | ✅ |
^{ | ✅ | ❌ |
图标由srip从www.flaticon.com制作。
使用reprexpy package生成的示例代码块。
- 项目
标签: