{"id":1352,"library":"azure-mgmt-advisor","title":"Azure Management Advisor","description":"The `azure-mgmt-advisor` library is the Microsoft Azure Advisor Client Library for Python. It provides a programmatic interface to interact with Azure Advisor, which offers personalized recommendations to help optimize Azure deployments for cost, performance, reliability, and security. Currently at version 9.0.0, it is part of the Azure SDK for Python, which follows a regular release cadence with updates typically occurring monthly.","status":"active","version":"9.0.0","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python","tags":["azure","cloud","management","advisor","recommendations"],"install":[{"cmd":"pip install azure-mgmt-advisor azure-identity","lang":"bash","label":"Install library and identity client"}],"dependencies":[{"reason":"Required for authentication with Azure services using modern credential flows.","package":"azure-identity","optional":false},{"reason":"Core shared classes and HTTP pipeline for Azure SDK libraries.","package":"azure-core","optional":false}],"imports":[{"note":"For versions prior to 3.0.0, the client was imported from a sub-module. Version 3.0.0 and later require direct import from `azure.mgmt.advisor`.","wrong":"from azure.mgmt.advisor.advisor_management_client import AdvisorManagementClient","symbol":"AdvisorManagementClient","correct":"from azure.mgmt.advisor import AdvisorManagementClient"},{"note":"As of v9.0.0b1 and later, `azure.common.credentials` and `msrestazure.azure_active_directory` are no longer supported for authentication. Use classes from `azure-identity` like `DefaultAzureCredential` instead.","wrong":"from azure.common.credentials import get_azure_cli_credentials","symbol":"DefaultAzureCredential","correct":"from azure.identity import DefaultAzureCredential"}],"quickstart":{"code":"import os\nfrom azure.identity import DefaultAzureCredential\nfrom azure.mgmt.advisor import AdvisorManagementClient\n\n# --- Authentication ---\n# For more info, see https://learn.microsoft.com/en-us/azure/developer/python/sdk/authentication-overview\n# Set AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET, and AZURE_SUBSCRIPTION_ID environment variables,\n# or authenticate via Azure CLI (az login).\n\ntry:\n    credential = DefaultAzureCredential()\n    subscription_id = os.environ.get(\"AZURE_SUBSCRIPTION_ID\", \"\")\n    if not subscription_id:\n        raise ValueError(\"AZURE_SUBSCRIPTION_ID environment variable not set.\")\nexcept Exception as e:\n    print(f\"Authentication setup failed: {e}\")\n    print(\"Please ensure you have authenticated to Azure (e.g., via `az login`) and set AZURE_SUBSCRIPTION_ID.\")\n    exit(1)\n\n# --- Client Initialization ---\nprint(f\"Initializing AdvisorManagementClient for subscription: {subscription_id}\")\nclient = AdvisorManagementClient(credential, subscription_id)\n\n# --- Fetching Recommendations ---\nprint(\"Listing Advisor recommendations:\")\ntry:\n    # The list() method returns an iterator over recommendations.\n    for recommendation in client.recommendations.list():\n        print(f\"  Category: {recommendation.category}\")\n        print(f\"  Impact: {recommendation.impact}\")\n        # Accessing nested properties like short_description.problem\n        if recommendation.short_description:\n            print(f\"  Problem: {recommendation.short_description.problem}\")\n            print(f\"  Solution: {recommendation.short_description.solution}\")\n        print(\"-\" * 20)\nexcept Exception as e:\n    print(f\"Failed to list recommendations: {e}\")","lang":"python","description":"This quickstart demonstrates how to authenticate with Azure using `DefaultAzureCredential` and list Azure Advisor recommendations for a given subscription. Ensure your Azure credentials and `AZURE_SUBSCRIPTION_ID` are set in your environment variables or via `az login`."},"warnings":[{"fix":"Migrate your authentication code to use `azure-identity`. Install it with `pip install azure-identity` and replace old credential types with `DefaultAzureCredential` or other appropriate `azure-identity` classes.","message":"The credential system was completely revamped in `9.0.0b1`. Legacy authentication methods like `azure.common.credentials` or `msrestazure.azure_active_directory` are no longer supported. You must use classes from `azure-identity` (e.g., `DefaultAzureCredential`).","severity":"breaking","affected_versions":"9.0.0b1 and later"},{"fix":"Update client instantiation from `Client(credentials, subscription_id, config=...)` to `Client(credential, subscription_id, enable_logging=...)` or similar keyword arguments supported by `azure-core`.","message":"Client initialization parameters changed in `9.0.0b1`. The `credentials` parameter was renamed to `credential`, and the `config` attribute no longer exists on client objects. Configuration should now be passed as keyword arguments to the client constructor.","severity":"breaking","affected_versions":"9.0.0b1 and later"},{"fix":"Review calls to LRO-initiating methods. Ensure they are prefixed with `begin_` (e.g., `client.resource.begin_create_or_update()`) and handle the new `LROPoller` return type from `azure.core.polling`.","message":"Long-running operations (LROs) now return an `azure.core.polling.LROPoller` object (instead of `msrest.polling.LROPoller`) and are typically prefixed with `begin_`.","severity":"breaking","affected_versions":"9.0.0b1 and later"},{"fix":"Update exception handling blocks to catch `azure.core.exceptions.HttpResponseError` instead of `CloudError` or other specific HTTP-related exceptions.","message":"The exception hierarchy has been simplified. Most exceptions now inherit from `azure.core.exceptions.HttpResponseError`. The `CloudError` class has been removed.","severity":"breaking","affected_versions":"9.0.0b1 and later"},{"fix":"Wrap client usage in a `with` statement (e.g., `with AdvisorManagementClient(...) as client:`) or explicitly call `client.close()` when done.","message":"HTTP connection pooling is enabled by default. To ensure proper resource management and avoid potential issues, client objects should ideally be used as context managers or have their `close()` method explicitly called when they are no longer needed.","severity":"gotcha","affected_versions":"3.0.0 and later"},{"fix":"Verify in the Azure Portal if recommendations exist for the specific category. When listing recommendations via SDK, you can apply a filter (e.g., `client.recommendations.list(filter=\"Category eq 'Security'\")`) to narrow down results.","message":"If you are not seeing expected Advisor recommendations for certain categories (e.g., 'Security'), ensure that there are actual recommendations in that category for your resources. You might need to explicitly filter the list operation if only specific categories are desired.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}