Forum Discussion
Anonymous
1 year agoNot applicable
Call semPy libraries as service principal
I have a notebook that I wish to get information from all datasets across my tenancy. I have been able to do this for workspaces my account has access to, but I need to do this for all workspaces. I ...
- Anonymous1 year ago
HI Anonymous,
After I double checked these credentials that we provide in the notebook. It seems not really used for the sempy functions authorizations.
They only initialed for Fabric RestClient and corresponding functions uses. For the default sempy functions, they still invoked the current user credentials that notebook and its sessions cached.
Regards,
Xiaoxin Sheng
ABI_Rufino
1 year agoAdvocate I
You are not properly creating the Token Provider.
Try this on a Fabric Notebook:
from azure.identity import ClientSecretCredential
from sempy.fabric import FabricRestClient
# Service principal credentials
tenant_id = "11111111-1111-1111-1111-111111111111"
client_id = "aaaaaaaa-bbbb-bbbb-cccc-cccccccccccc"
client_secret = "aaaaaaaa-bbbb-bbbb-cccc-dddddddddddd"
workspace_id ='aaaaaaaa-bbbb-cccc-dddd-dddddddddddd'
# Create a token provider
class ServicePrincipalTokenProvider:
def __init__(self, tenant_id, client_id, client_secret):
self.credential = ClientSecretCredential(
tenant_id=tenant_id,
client_id=client_id,
client_secret=client_secret
)
self.scope = "https://analysis.windows.net/powerbi/api/.default"
def __call__(self):
token = self.credential.get_token(self.scope)
return token.token
token_provider = ServicePrincipalTokenProvider(tenant_id, client_id, client_secret)
client = FabricRestClient(token_provider=token_provider)
# Example REST call (e.g., list workspaces)
response = client.get("/v1/workspaces")
# print(response.json())
# Another example REST call (e.g., datasets on a workspace)
response = client.get(f"/v1/workspaces/{workspace_id}/items")
# print(response.json())