Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save amalgjose/70f7deafea30626433812005e64ae74d to your computer and use it in GitHub Desktop.
Save amalgjose/70f7deafea30626433812005e64ae74d to your computer and use it in GitHub Desktop.
A Python program to connect to Azure ADLS Gen2 (Storage Account) using azure service principle instead of the connection string.
from azure.identity import ClientSecretCredential
from azure.storage.blob import BlobServiceClient
# Tenant ID for your Azure Subscription
TENANT_ID = "85XXX93e-XXXX-XXXX-XXXXX-96150XXX893e"
# Your Service Principal App ID (Client ID)
CLIENT_ID = "a3XXX40d-xxxxxxx-0ff72XXXX66a"
# Your Service Principal Password (Client Secret)
CLIENT_SECRET = "5XXXIdPxGEXXXX_1H8XXy0kao_7"
ACCOUNT_NAME = "azXXXxxxXX"
CONTAINER_NAME = "XXXXXXXXXX"
credentials = ClientSecretCredential(TENANT_ID, CLIENT_ID, CLIENT_SECRET)
blobService = BlobServiceClient(
"https://{}.blob.core.windows.net".format(ACCOUNT_NAME),
credential=credentials
)
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: " + blob.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment