Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.
Check it out now!Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more
03-24-2025 15:20 PM - last edited 03-27-2025 13:08 PM
Download this notebook from: semantic-link-labs/notebooks/Service Principal.ipynb at main · microsoft/semantic-link-labs · GitHub
Check here to see the latest version.
%pip install semantic-link-labs
Here are additional instructions regarding admin read-only APIs. Make sure to read and follow these instructions.
For connecting to Azure Analysis Services (AAS) via Service Principal, add the Service Principal (app) as an admin the AAS instance either in the Azure Portal or using SSMS in this format: app:<clientid>@<tenantid>.
Authentication to retrieve the Key Vault secrets is made using the account which is executing the notebook so please make sure that this account has access to the Key Vault.
import sempy_labs as labs from sempy_labs import admin, graph from sempy_labs.tom import connect_semantic_model key_vault_uri = '' # Enter your key vault URI key_vault_tenant_id = '' # Enter the key vault key to the secret storing your Tenant ID key_vault_client_id = '' # Enter the key vault key to the secret storing your Client ID (Application ID) key_vault_client_secret = '' # Enter the key vault key to the secret storing your Client Secret
with labs.service_principal_authentication( key_vault_uri=key_vault_uri, key_vault_tenant_id=key_vault_tenant_id, key_vault_client_id=key_vault_client_id, key_vault_client_secret=key_vault_client_secret): df = admin.list_capacities() display(df)
with labs.service_principal_authentication( key_vault_uri=key_vault_uri, key_vault_tenant_id=key_vault_tenant_id, key_vault_client_id=key_vault_client_id, key_vault_client_secret=key_vault_client_secret): df = labs.list_subscriptions() display(df)
with labs.service_principal_authentication( key_vault_uri=key_vault_uri, key_vault_tenant_id=key_vault_tenant_id, key_vault_client_id=key_vault_client_id, key_vault_client_secret=key_vault_client_secret): labs.suspend_fabric_capacity( capacity='', azure_subscription_id='', resource_group='', )
with labs.service_principal_authentication( key_vault_uri=key_vault_uri, key_vault_tenant_id=key_vault_tenant_id, key_vault_client_id=key_vault_client_id, key_vault_client_secret=key_vault_client_secret): df = graph.list_users() display(df)
Note that the Service Principal must have at least read permission to the semantic model to which it is connecting. See here for more details.
dataset = '' # Enter the name of the semantic model workspace = None # Enter the name of the workspace (for Azure Analysis Serivces instance use this format: "asazure://.asazure.windows.net/")
with labs.service_principal_authentication( key_vault_uri=key_vault_uri, key_vault_tenant_id=key_vault_tenant_id, key_vault_client_id=key_vault_client_id, key_vault_client_secret=key_vault_client_secret): with connect_semantic_model(dataset=dataset, workspace=workspace, readonly=True) as tom: for t in tom.model.Tables: print(t.Name)
https%3A%2F%2Fgithub.com%2Fmicrosoft%2Fsemantic-link-labs%2Fblob%2Fmain%2Fnotebooks%2FService%2520Principal.ipynb