adlfs
adlfs provides an fsspec-compatible interface for accessing Azure Blob Storage, Azure Data Lake Storage Gen2, and the now-deprecated Azure Data Lake Storage Gen1. It allows Python users to interact with Azure storage as if it were a local filesystem, integrating seamlessly with data processing libraries like Dask, Pandas, and Ray. The library is currently at version 2026.2.0 and maintains an active release schedule.
Warnings
- breaking ADLS Gen1 (adl:// protocol and AzureDatalakeFileSystem class) has been officially retired. Operations using these interfaces are obsolete.
- breaking Starting in a future release, adlfs will require explicit credentials by default. Anonymous access will no longer be the implicit default.
- gotcha Authentication can be complex due to multiple methods (account key, SAS token, service principal, `DefaultAzureCredential`, connection string). Misconfiguring these or incorrect permissions are common issues.
- breaking Support for Python 3.9 has been removed.
- gotcha By default, write operations create BlockBlobs which cannot be appended to. AppendBlobs (using `mode="ab"`) are also not available if hierarchical namespaces are enabled on the storage account.
Install
-
pip install adlfs -
conda install -c conda-forge adlfs
Imports
- AzureBlobFileSystem
from adlfs import AzureBlobFileSystem
- AzureDatalakeFileSystem
from adlfs import AzureDatalakeFileSystem
Quickstart
import os
from adlfs import AzureBlobFileSystem
# Recommended: Use environment variables for credentials
# e.g., AZURE_STORAGE_ACCOUNT_NAME, AZURE_STORAGE_ACCOUNT_KEY, AZURE_STORAGE_SAS_TOKEN
# For DefaultAzureCredential, ensure AZURE_STORAGE_ACCOUNT_NAME is set and anon=False
account_name = os.environ.get('AZURE_STORAGE_ACCOUNT_NAME', 'your_account_name')
# For demonstration, using anonymous access to a public container
# In real scenarios, provide proper credentials (account_key, sas_token, or use anon=False)
fs = AzureBlobFileSystem(account_name=account_name, anon=True)
# Example: List contents of a public container
container_name = "azureopendatastorage" # A known public container
path_to_list = f"az://{container_name}/"
try:
print(f"Listing contents of {path_to_list}:")
contents = fs.ls(path_to_list, detail=False)
for item in contents[:5]: # Print first 5 items
print(item)
if not contents: print("Container is empty or access denied (check credentials/permissions).")
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure 'AZURE_STORAGE_ACCOUNT_NAME' is set, or if accessing a private container, provide valid credentials.")
# Example: Read a file (requires appropriate permissions)
# Replace with a real path if you have authenticated access
# file_path = f"az://{container_name}/path/to/your/file.txt"
# try:
# with fs.open(file_path, 'rb') as f:
# data = f.read()
# print(f"\nContent of {file_path[:50]}...: {data.decode()[:100]}...")
# except Exception as e:
# print(f"\nCould not read file {file_path[:50]}...: {e}")