Forum Discussion
Authentication in Fabric User Defined Function
- 6 months ago
Hello diablo9081
Create a connection to your target Lakehouse inside your UDF item (Manage connections > Add data connection). Note the generated alias; you’ll have to put it in the decorator. Lakehouse connections provide read/write to Files.
Add libraries to the UDF item (Toolbar → Library management):
polars (for the DataFrame)
Publish the library changes. Public PyPI packages are supported in UDFs.
In a User data functions (UDF) item you don’t have NotebookUtils (the usual way to get a bearer token). You can use the following code that uses a SPN to authenticate -from azure.identity import ClientSecretCredential from azure.storage.filedatalake import DataLakeServiceClient tenant_id = "<tenant_guid>" client_id = "<app_client_id>" client_secret= "<client_secret>" cred = ClientSecretCredential(tenant_id, client_id, client_secret) svc = DataLakeServiceClient( account_url="https://onelake.dfs.fabric.microsoft.com", credential=cred )
Hello diablo9081
Create a connection to your target Lakehouse inside your UDF item (Manage connections > Add data connection). Note the generated alias; you’ll have to put it in the decorator. Lakehouse connections provide read/write to Files.
Add libraries to the UDF item (Toolbar → Library management):
polars (for the DataFrame)
Publish the library changes. Public PyPI packages are supported in UDFs.
from azure.identity import ClientSecretCredential
from azure.storage.filedatalake import DataLakeServiceClient
tenant_id = "<tenant_guid>"
client_id = "<app_client_id>"
client_secret= "<client_secret>"
cred = ClientSecretCredential(tenant_id, client_id, client_secret)
svc = DataLakeServiceClient(
account_url="https://onelake.dfs.fabric.microsoft.com",
credential=cred
)