femi
femi

Reputation: 984

Connecting to ADLS Gen 2 using Service Principals

Can anyone show any python code I can use to connect to ADLS Gen 2 using Service principals

Upvotes: 1

Views: 1965

Answers (1)

Ivan Glasenberg
Ivan Glasenberg

Reputation: 29985

First, install the following libraries:

azure-storage-file-datalake

azure-identity

Then use the code below:

from azure.storage.filedatalake import DataLakeServiceClient
from azure.identity import ClientSecretCredential

tenant_id="xxx"
client_id="xxx"
client_secret="xxx"

credential = ClientSecretCredential(tenant_id,client_id,client_secret)
service = DataLakeServiceClient(account_url="https://xxx.dfs.core.windows.net/",credential=credential)

#create a file system in ADLS Gen2
file_system_client = service.create_file_system(file_system="myfileSystem")

More code examples are here.

Upvotes: 2

Related Questions