未提供项目说明

cloudpathlib的Python项目详细描述


Docs StatusPyPIconda-forgetestscodecov

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_textwrite_bytes.open('w')方法都可以将更改上载到云存储,而不需要作为开发人员进行任何额外的文件管理。在
  • 无缝缓存:文件仅在必要时在本地下载。您还可以轻松地传递持久缓存文件夹,以便跨进程和会话重新下载所需的内容。在
  • Tested:全面的测试套件和代码覆盖率。在

安装

cloudpathlib依赖于云服务的sdk(例如,boto3azure-storage-blob)与各自的存储服务通信。如果您尝试为没有安装依赖项的云服务使用云路径,cloudpathlib将出错并告诉您需要安装什么。在

要在安装cloudpathlib时安装云服务的SDK依赖项,需要使用pip的"extras"规范来指定它。例如:

^{pr2}$

当前支持的云存储服务有:azures3。您还可以使用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^{}^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}
^{}

图标由sripwww.flaticon.com制作。
使用reprexpy package生成的示例代码块。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java文件分块,获取长度字节   java嵌入式Tomcat不执行jsf页面   java我的数据库中有2个实体,但hibernate返回其中6个。   java如何基于逗号拆分字符串   java取消已经运行的CompletableFutures的预期模式是什么   java如何在informix中从另一个数据库复制表ddl和数据   为什么图片是黑色的?   java根据字符串数组中的单词筛选列表   Java8的集合。平行流有效吗?   Kotlin中的java静态内部类   java如何在GUI中生成一列字符串   javafx如何正确使用高对比度主题?   带空格的javascript Httpurlconnection参数   java如何设置GridBagLayout的约束   java如何在一个线程可能尚未初始化时关闭另一个线程   java将简单时间格式转换为特殊时间格式(hhmmt)   安卓/java阵列重复过滤器的问题   java在队列的链接实现下,入队和出队是如何工作的   java更新sql外键约束