有没有类似s3fs的Python库可用于Azure Blob Storage打开文件句柄?
适用于Azure Blob Storage的类似s3fs的Python库
当然有,以下是两个常用的选项:
1. azure-storage-blob(官方SDK)
这是Azure官方提供的Blob存储Python库,支持以文件句柄形式读取Blob内容,用法如下:
from azure.storage.blob import BlobServiceClient, BlobClient # 初始化Blob客户端 blob_service_client = BlobServiceClient.from_connection_string("你的Azure存储账户连接字符串") blob_client = blob_service_client.get_blob_client(container="my-container", blob="my-file.txt") # 以文件句柄形式读取内容 with blob_client.open_read() as f: print(f.read())
2. fsspec(兼容Azure Blob的文件系统抽象库)
你熟悉的s3fs就是基于fsspec开发的,而fsspec本身支持Azure Blob Storage后端,用法和s3fs非常相似,学习成本低:
import fsspec # 初始化Azure Blob文件系统 fs = fsspec.filesystem('az', account_name="你的存储账户名", account_key="你的存储账户密钥") # 以文件句柄形式读取Blob with fs.open('my-container/my-file.txt', 'rb') as f: print(f.read())
内容的提问来源于stack exchange,提问作者Kevin Tianyu Xu
相关产品推荐
相关产品推荐

