adlfs

2026.2.0 · active · verified Mon Apr 06

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

Install

Imports

Quickstart

This quickstart demonstrates how to initialize `adlfs.AzureBlobFileSystem` and list contents of a public Azure Blob Storage container. For private containers, authentication relies on `storage_options` parameters (like `account_key`, `sas_token`, `connection_string`, or service principal details) or automatic credential resolution via `DefaultAzureCredential` (by setting `anon=False` and ensuring `AZURE_STORAGE_ACCOUNT_NAME` is set).

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}")

view raw JSON →