通过ossfs fsspec 扩展访问oss 数据

尽管oss 对于s3 客户端具有兼容性,直接通过s3fs 是可以直接访问oss 的,但是有不少缺陷(比如ls 的支持就有问题)ossfs 是基于oss client 实现的标准
fsspec 扩展,使用上很不错,对于文件系统常见操作支持的很好,以下是一个简单使用说明

参考使用

  • 安装
pip install ossfs 
  • 代码使用
    直接基于了标准fsspec,自动进行protocol 发现
    demo.py
import fsspec
fs = fsspec.filesystem('oss',endpoint='https://oss-cn-beijing.aliyuncs.com',key="xxxxx",secret="xxxx")
ls_fs = fs.ls('/ollama-beijing/')
print(ls_fs)

直接使用OSSFileSystem 类的

import ossfs
fs = ossfs.OSSFileSystem(endpoint='https://oss-cn-beijing.aliyuncs.com',key="xxxxx",secret="xxxx")
ls_fs  = fs.ls('/ollama-beijing/')
print(ls_fs)

说明

基于ossfs 进行oss 的访问还是很方便的,对于一些数据分析场景,需要使用oss 的,尤其是基于python 处理框架的很值得尝试下,当然官方基于fuse 的
ossfs 也是一个不错的选择值得使用下 ,尤其是希望直接挂载s3 数据 为文件系统的

参考资料

https://github.com/fsspec/ossfs
https://filesystem-spec.readthedocs.io/en/latest/usage.html
https://github.com/aliyun/ossfs
https://s3fs.readthedocs.io/en/latest/
https://github.com/fsspec/s3fs

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

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2023-09-26 nginx-clojure nginx 1.25.2 版本docker 镜像
2022-09-26 JadConfig classpathRepository 扩展
2021-09-26 cube.js websocket 实时数据更新说明
2020-09-26 gopacket 流量抓包golang 包
2018-09-26 stenciljs 学习六 组件开发样式指南
2018-09-26 stenciljs 学习五 事件
2018-09-26 stenciljs 学习四 组件装饰器

导航

< 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
点击右上角即可分享
微信分享提示