Recently I got a requirement to connect to ADLS Gen2 and download all the files from ADLS to a linux machine. I had prepared a python program that connects to the storage account using connection string. But when I requested the connection string, the IT team told me that they cannot provide the connection string and they requested me to connect using a service principle. So I had to modify the program to make it connect using service principle.

We need two python packages to run this program. The packages are given below.


The core part of the program that establishes connection to the storage account is given below.

from azure.identity import ClientSecretCredential
from import BlobServiceClient
# Tenant ID for your Azure Subscription
# Your Service Principal App ID (Client ID)
CLIENT_ID = "a3XXX40d-xxxxxxx-0ff72XXXX66a"
# Your Service Principal Password (Client Secret)
credentials = ClientSecretCredential(TENANT_ID, CLIENT_ID, CLIENT_SECRET)
blobService = BlobServiceClient(
print("\n==============LIST OF ALL BLOBS=================")
# Path in the container. If you want to list everything in the root path, keep it empty
prefix = ""
container = blobService.get_container_client(CONTAINER_NAME)
for blob in container.list_blobs(name_starts_with=prefix):
print("\t Blob name: " +

I hope this tip helps someone šŸ™‚ . Feel free to comment if you have any questions.