Azure / azure-sdk-for-python

This repository is for active development of the Azure SDK for Python. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/python/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-python.
MIT License
4.63k stars 2.84k forks source link

AzureML SDK - No module named 'azure.ai.ml.entities._datastore.credentials' #37704

Open edgBR opened 1 month ago

edgBR commented 1 month ago

Describe the bug It seems that documentation is incorrect regarding AzureML Datastores as the SDK component doesnt exist

To Reproduce Steps to reproduce the behavior:

  1. Follow this link: https://learn.microsoft.com/en-us/azure/machine-learning/how-to-datastore?view=azureml-api-2&tabs=sdk-account-key%2Csdk-adls-sp%2Csdk-azfiles-accountkey%2Csdk-adlsgen1-identity-access%2Csdk-onelake-sp#create-an-azure-data-lake-storage-gen2-datastore

Run the following:

from azure.ai.ml.entities import AzureDataLakeGen2Datastore
from azure.ai.ml.entities._datastore.credentials import ServicePrincipalCredentials

from azure.ai.ml import MLClient

ml_client = MLClient.from_config()

store = AzureDataLakeGen2Datastore(
    name="adls_gen2_example",
    description="Datastore pointing to an Azure Data Lake Storage Gen2.",
    account_name="mytestdatalakegen2",
    filesystem="my-gen2-container",
     credentials=ServicePrincipalCredentials(
        tenant_id= "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
        client_id= "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
        client_secret= "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    ),
)

ml_client.create_or_update(store)

It will break in:

image

Expected behavior I expect the documentation to be correct.

github-actions[bot] commented 1 month ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @Azure/azure-ml-sdk @azureml-github.

edgBR commented 1 month ago

Hi, any feedback on this?

LukePWilkins commented 1 month ago

Hello. Experiencing the same, while running through the SDKv2 examples - https://github.com/Azure/azureml-examples/blob/main/sdk/python/resources/datastores/datastore.ipynb

{
    "name": "ModuleNotFoundError",
    "message": "No module named 'azure.ai.ml.entities._datastore.credentials'",
    "stack": "---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[7], line 11
      4 from azure.ai.ml import command, Input
      5 from azure.ai.ml.entities import (
      6     AzureBlobDatastore,
      7     AzureFileDatastore,
      8     AzureDataLakeGen1Datastore,
      9     AzureDataLakeGen2Datastore,
     10 )
---> 11 from azure.ai.ml.entities._datastore.credentials import (
     12     AccountKeyCredentials,
     13     SasTokenCredentials,
     14     ServicePrincipalCredentials,
     15 )
     16 from azure.ai.ml.entities import Environment

ModuleNotFoundError: No module named 'azure.ai.ml.entities._datastore.credentials'"
}
LukePWilkins commented 1 month ago

Referencing this link - https://learn.microsoft.com/en-us/azure/machine-learning/how-to-datastore?view=azureml-api-2&tabs=sdk-identity-based-access%2Csdk-adls-identity-access%2Csdk-azfiles-accountkey%2Csdk-adlsgen1-identity-access%2Csdk-onelake-identity-access

I rewrote to

# from azure.ai.ml.entities._datastore.credentials import (
#     AccountKeyCredentials,
#     SasTokenCredentials,
#     ServicePrincipalCredentials,
# )

# added - 16/10/2024 - Luke Wilkins
from azure.ai.ml.entities import (
    AccountKeyConfiguration,
    SasTokenConfiguration,
    ServicePrincipalConfiguration
)
blob_datastore1 = AzureBlobDatastore(
    name="lwrwmachinemachinestore",
    description="Datastore for lovely MachineMachine.",
    account_name="lwrwmachinemachinestore",
    container_name="data-container",
    credentials=AccountKeyConfiguration(
        account_key="xxxxxxxxxxx"
    )
    # credentials=AccountKeyCredentials(
    #     account_key="XXXxxxXXXxXXXXxxXXXXXxXXXXXxXxxXxXXXxXXXxXXxxxXXxxXXXxXxXXXxxXxxXXXXxxxxxXXxxxxxxXXXxXXX"
    #),
)
ml_client.create_or_update(blob_datastore1)

Confirm dataStore is created via sighting in the portal.