{"library":"azure-mgmt-compute","title":"Azure Compute Management Client Library for Python","description":"The `azure-mgmt-compute` library is the Microsoft Azure Compute Management Client Library for Python, providing essential functionality for managing Azure compute resources like Virtual Machines, Virtual Machine Scale Sets, Disks, and Galleries. It enables developers to create, configure, manage, and scale Windows and Linux virtual machines programmatically. Currently at version 37.2.0, the library is actively maintained with frequent updates, often on a monthly or bi-monthly release cadence, reflecting ongoing development in the Azure platform.","status":"active","version":"37.2.0","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/compute/azure-mgmt-compute","tags":["Azure","Cloud","Compute","Virtual Machines","VM Scale Sets","Management","SDK"],"install":[{"cmd":"pip install azure-mgmt-compute azure-identity","lang":"bash","label":"Install with authentication library"}],"dependencies":[{"reason":"Required for Azure Active Directory token authentication with modern Azure SDKs.","package":"azure-identity","optional":false},{"reason":"Underlying shared utilities; specific versions can cause import errors.","package":"azure-common","optional":false}],"imports":[{"symbol":"ComputeManagementClient","correct":"from azure.mgmt.compute import ComputeManagementClient"},{"symbol":"DefaultAzureCredential","correct":"from azure.identity import DefaultAzureCredential"},{"note":"The '.models' method on ComputeManagementClient was removed in a breaking change; models should now be imported directly from 'azure.mgmt.compute.models'.","wrong":"client.models","symbol":"models","correct":"from azure.mgmt.compute import models"}],"quickstart":{"code":"import os\nfrom azure.identity import DefaultAzureCredential\nfrom azure.mgmt.compute import ComputeManagementClient\n\n# Set environment variables for authentication and subscription ID\n# AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET\n# AZURE_SUBSCRIPTION_ID\n\nsubscription_id = os.getenv(\"AZURE_SUBSCRIPTION_ID\", \"\")\nif not subscription_id:\n    print(\"Please set the AZURE_SUBSCRIPTION_ID environment variable.\")\n    exit(1)\n\n# Authenticate using DefaultAzureCredential (looks for env vars, managed identity, etc.)\ncredential = DefaultAzureCredential()\n\n# Create a Compute Management Client\ncompute_client = ComputeManagementClient(credential, subscription_id)\n\ntry:\n    # List all virtual machines in the subscription\n    print(\"Listing all virtual machines:\")\n    for vm in compute_client.virtual_machines.list_all():\n        print(f\"- VM Name: {vm.name}, Location: {vm.location}\")\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Ensure you have set AZURE_SUBSCRIPTION_ID and have appropriate permissions.\")\n","lang":"python","description":"This quickstart initializes the `ComputeManagementClient` using `DefaultAzureCredential` for authentication, which is the recommended approach for Azure SDKs. It then proceeds to list all virtual machines accessible within the specified Azure subscription. Ensure `AZURE_SUBSCRIPTION_ID` and other necessary Azure Identity environment variables (e.g., `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`) are set for successful authentication."},"warnings":[{"fix":"Remove explicit API version imports (e.g., `from azure.mgmt.compute.v20xx_xx_xx import ComputeManagementClient`). Instead, import `ComputeManagementClient` directly from `azure.mgmt.compute`. Import models directly from `azure.mgmt.compute.models`. If your application requires a specific non-latest API-Version, pin to an older package version.","message":"The library no longer includes API version subfolders (e.g., `v20xx_xx_xx` modules) and only targets the latest API-Version available on Azure. Importing models via `client.models` is also removed.","severity":"breaking","affected_versions":">=30.0.0"},{"fix":"Migrate to `azure-identity` library for authentication. Use `DefaultAzureCredential` or other credential types from `azure.identity` to create the client. Ensure `azure-identity` is installed: `pip install azure-identity`.","message":"The authentication mechanism for Azure SDKs was redesigned. Older versions used `ServicePrincipalCredentials` from `azure.common`, which is no longer supported.","severity":"breaking","affected_versions":">=20.0.0"},{"fix":"Update all calls to Azure Compute methods to pass query and header parameters as keyword arguments, not positional arguments.","message":"All query and header parameters are now keyword-only, enforcing more explicit function calls.","severity":"breaking","affected_versions":">=30.0.0"},{"fix":"Ensure `azure-common` is updated to a compatible version (e.g., `pip install --upgrade azure-common`) or install `azure-common==1.1.23` if you are using an older Python environment like Python 3.8 where specific issues were noted.","message":"`ModuleNotFoundError: No module named 'azure.profiles'` can occur if `azure-common` is an older version than expected by `azure-mgmt-compute`.","severity":"gotcha","affected_versions":"<37.0.0"},{"fix":"This often requires ensuring the client library and the Azure service API are in sync. If possible, upgrade `azure-mgmt-compute` to the latest version. If persistent, check the Azure status page or report to the Azure SDK team, providing the full error traceback and request details. Consider adding retry logic for transient errors.","message":"Intermittent `DeserializationError` can occur when retrieving VM details, sometimes linked to API version mismatches or unexpected responses.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Implement proper lifecycle management for Azure resources created programmatically. Use Azure Resource Tags, monitor resource usage with Azure Monitor, and regularly review your Azure spending to identify idle or orphaned resources. Leverage Azure Policy to enforce standards.","message":"Resource and cost management can be challenging. Unmonitored or over-provisioned resources lead to unexpected Azure bills.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-06T00:00:00.000Z","next_check":"2026-07-05T00:00:00.000Z"}