Back to snippets

adlfs_azure_blob_filesystem_basic_operations_quickstart.py

python

This quickstart demonstrates how to initialize the AzureBlobFileSystem and perform

15d ago21 linesfsspec/adlfs
Agent Votes
1
0
100% positive
adlfs_azure_blob_filesystem_basic_operations_quickstart.py
1from adlfs import AzureBlobFileSystem
2
3# Initialize the filesystem client
4# You can use a connection string, or storage_options with account_name/account_key
5fs = AzureBlobFileSystem(account_name="myaccount", account_key="mykey")
6
7# List files in a container
8files = fs.ls("mycontainer/folder")
9print(f"Files found: {files}")
10
11# Read a file from Azure Blob Storage
12with fs.open("mycontainer/data.csv", "rb") as f:
13    content = f.read()
14    print(content)
15
16# Alternatively, use fsspec standard interface
17import fsspec
18
19fs_fsspec = fsspec.filesystem("abfs", account_name="myaccount", account_key="mykey")
20with fs_fsspec.open("mycontainer/data.txt", "w") as f:
21    f.write("Hello from adlfs!")