Registry / azure / azure-mgmt-compute

azure-mgmt-compute

JSON →
library38.3.0pypypi✓ verified 26d ago

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.

pip install azure-mgmt-compute azure-identity
INSTALL
IMPORT
SIG · AZURE-MGMT-COMPUTE
A
azure-mgmt-compute
azurepythonv38.3.0
Install
4.4s avg
Import
1049ms
Disk
54MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v38.3.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 1.082s · 54MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 4.4s · import 1.016s · 54MB
54MB installed
● package 54MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ComputeManagementClient
from azure.mgmt.compute import ComputeManagementClient
DefaultAzureCredential
from azure.identity import DefaultAzureCredential
models
from azure.mgmt.compute import models
client.models
The '.models' method on ComputeManagementClient was removed in a breaking change; models should now be imported directly from 'azure.mgmt.compute.models'.

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.

import os from azure.identity import DefaultAzureCredential from azure.mgmt.compute import ComputeManagementClient # Set environment variables for authentication and subscription ID # AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET # AZURE_SUBSCRIPTION_ID subscription_id = os.getenv("AZURE_SUBSCRIPTION_ID", "") if not subscription_id: print("Please set the AZURE_SUBSCRIPTION_ID environment variable.") exit(1) # Authenticate using DefaultAzureCredential (looks for env vars, managed identity, etc.) credential = DefaultAzureCredential() # Create a Compute Management Client compute_client = ComputeManagementClient(credential, subscription_id) try: # List all virtual machines in the subscription print("Listing all virtual machines:") for vm in compute_client.virtual_machines.list_all(): print(f"- VM Name: {vm.name}, Location: {vm.location}") except Exception as e: print(f"An error occurred: {e}") print("Ensure you have set AZURE_SUBSCRIPTION_ID and have appropriate permissions.")
Debug
Known issues
breakingThe 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.
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.
affects: >=30.0.0
breakingThe authentication mechanism for Azure SDKs was redesigned. Older versions used `ServicePrincipalCredentials` from `azure.common`, which is no longer supported.
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`.
affects: >=20.0.0
breakingAll query and header parameters are now keyword-only, enforcing more explicit function calls.
fix
Update all calls to Azure Compute methods to pass query and header parameters as keyword arguments, not positional arguments.
affects: >=30.0.0
gotcha`ModuleNotFoundError: No module named 'azure.profiles'` can occur if `azure-common` is an older version than expected by `azure-mgmt-compute`.
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.
affects: <37.0.0
gotchaIntermittent `DeserializationError` can occur when retrieving VM details, sometimes linked to API version mismatches or unexpected responses.
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.
affects: All versions
gotchaResource and cost management can be challenging. Unmonitored or over-provisioned resources lead to unexpected Azure bills.
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.
affects: All versions
gotchaThe Azure SDK requires the `AZURE_SUBSCRIPTION_ID` environment variable to be set for many operations to identify the target subscription. Without it, client initialization or subsequent operations will fail with an error indicating the variable is missing.
fix
Set the `AZURE_SUBSCRIPTION_ID` environment variable in your environment (e.g., `export AZURE_SUBSCRIPTION_ID='<your-subscription-id>'` for Linux/macOS, or via system settings/CI environment variables). Ensure your subscription ID is a valid GUID.
affects: All versions
gotchaThe `AZURE_SUBSCRIPTION_ID` environment variable is not set. Many Azure SDK operations require this to identify which subscription to target.
fix
Set the `AZURE_SUBSCRIPTION_ID` environment variable before running your application. You can obtain your subscription ID from the Azure portal or CLI. Example: `export AZURE_SUBSCRIPTION_ID='<your_subscription_id>'` (for Linux/macOS) or `set AZURE_SUBSCRIPTION_ID=<your_subscription_id>` (for Windows CMD).
affects: All versions
Upgrade
Version history
38.3.0latest on PyPI · released Aug 19, 2026
Audit
Dependencies
azure-identityrequiredRequired for Azure Active Directory token authentication with modern Azure SDKs.
azure-commonrequiredUnderlying shared utilities; specific versions can cause import errors.
Agent activity
43 hits · last 30 days
node
38
OpenAI (training)
1
Resources
azure-mgmt-compute — pip install azure-mgmt-compute · libregistry