cloudpathlib 简单试用

通过minio 作为s3 存储进行测试

s3 准备

  • docker-compose
version: "3"
services:
  s3:
    image: minio/minio:latest
    ports:
    - 9000:9000
    - 9001:9001
    command: server /data --console-address ":9001"

使用

  • 安装依赖
pip install cloudpathlib[s3]
  • 代码集成
from cloudpathlib import S3Client,CloudPath
# 使用s3 client  配置minio 地址
client = S3Client(aws_access_key_id="minio", aws_secret_access_key="minio123",endpoint_url="http://localhost:9000")
 
cp1 = CloudPath("s3://demo/user01/demo.txt", client=client)
 
with cp1.open("w",) as f:
    f.write("My new text!")
 
with cp1.open("r") as f:
    print(f.read())
 
for cp in (cp0).glob("**/*.txt"):
    print(cp)
  • 效果

说明

以上只是简单得试用,实际上cloudpathlib 支持的标准pathlib 能力的同时还提供了不少其他功能,很值得尝试下

参考资料

https://github.com/drivendataorg/cloudpathlib
https://cloudpathlib.drivendata.org/
https://cloudpathlib.drivendata.org/stable/api-reference/cloudpath/

posted on   荣锋亮  阅读(18)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2022-10-29 dremio 23 版本 udf 可以使用了
2019-10-29 gtibase rpm包制作
2018-10-29 hasura 的3factor 架构结论
2018-10-29 citus real-time 分析demo( 来自官方文档)
2018-10-29 citus 多租户应用开发(来自官方文档)

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示