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/