用于打开 Azure Blob 存储对象的文件句柄的 Python 库,类似于 AWS S3 的 s3fs 库

问题描述 投票:0回答:1

对于 AWS S3,有一个名为 s3fs 的 Python 库,可以打开 S3 对象的文件句柄。

例如

import s3fs
s3 = s3fs.S3FileSystem(anon=True)
with s3.open('my-bucket/my-file.txt', 'rb') as f:
    print(f.read())

Azure Blob 存储有类似的东西吗?

python azure-blob-storage
1个回答
0
投票

Azure Blob 存储有类似的东西吗?

截至目前,azure-storage-blob Python 库可用于打开 Azure Blob 存储对象的文件句柄。

或者,您可以使用

fsspec
从 Azure Blob 存储读取文本文件。

代码:

import fsspec

account_name = "venkat789"
account_key = "zzzzz"

with fsspec.open(f'abfss://<container name>/readfile.txt', account_name=account_name, account_key=account_key) as f:
    data = f.read().decode('utf-8')
    print(data)

上面的代码使用

fsspec
库从 Azure Blob 存储读取文件。它使用
account_name
account_key
变量进行身份验证。
fsspec.open()
函数用于打开位于
abfss://sample/readfile.txt
的文件。使用
f.read()
读取文件内容并使用
decode()
转换为字符串。最后,使用
print()
将文件内容打印到控制台。

输出:

Hello there, Azure Storage. I'm a friendly file ready to be stored in a blob.

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.