Install & Compatibility
Where this runs
tested against v6.0.1 · 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
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 43.4MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 3.8s · import 0.000s · 44MB
42MB installed
● package 42MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
CommerceManagementClient
✓ from azure.mgmt.commerce import CommerceManagementClient
UsageManagementClient
✓ from azure.mgmt.commerce import UsageManagementClient
DefaultAzureCredential
✓ from azure.identity import DefaultAzureCredential
✗ from azure.common.credentials import UserPassCredentials
Azure SDK v6.0.0+ deprecated azure.common.credentials and requires azure-identity for authentication.
This quickstart demonstrates how to authenticate with Azure using `DefaultAzureCredential`, create a `UsageManagementClient`, and then retrieve daily usage aggregates and rate card information for your Azure subscription. Ensure you have the `AZURE_SUBSCRIPTION_ID` environment variable set and appropriate Azure permissions (e.g., Reader role on the subscription).
import os
from datetime import date, timedelta
from azure.identity import DefaultAzureCredential
from azure.mgmt.commerce import UsageManagementClient
# Set your Azure Subscription ID
# You can set this as an environment variable or replace directly
subscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', 'YOUR_SUBSCRIPTION_ID')
if subscription_id == 'YOUR_SUBSCRIPTION_ID':
print("Please set the 'AZURE_SUBSCRIPTION_ID' environment variable or replace 'YOUR_SUBSCRIPTION_ID' in the code.")
else:
try:
# Authenticate using DefaultAzureCredential (supports various auth methods)
credential = DefaultAzureCredential()
# Create a CommerceManagementClient
commerce_client = UsageManagementClient(credential, subscription_id)
# Get usage aggregates for the last day
end_date = date.today()
start_date = end_date - timedelta(days=1)
print(f"Retrieving usage aggregates from {start_date} to {end_date}...")
usage_iterator = commerce_client.usage_aggregates.list(
str(start_date) + 'T00:00:00Z',
str(end_date) + 'T00:00:00Z'
)
print("\nDaily Usage Aggregates:")
for item in usage_iterator:
print(f" Resource: {item.properties.meter_details.meter_name}, Quantity: {item.properties.quantity}, Unit: {item.properties.unit_of_measure}")
# Example: Get Rate Card for a specific offer and region
# OfferDurableID example: 'MS-AZR-0062P' for Pay-As-You-Go
# This query string needs to be carefully constructed based on desired filters
# For available OfferDurableIDs, refer to Azure documentation
# Example query string for a specific offer, currency, locale, and region
rate_card_query = "OfferDurableId eq 'MS-AZR-0062P' and Currency eq 'USD' and Locale eq 'en-US' and RegionInfo eq 'US'"
print(f"\nGetting rate card for: {rate_card_query}")
rate_card = commerce_client.rate_card.get(rate_card_query)
if rate_card.meters:
print("First 3 Rate Card Meters (if available):")
for i, meter in enumerate(rate_card.meters):
if i >= 3: break
print(f" Meter: {meter.meter_name}, Unit: {meter.unit}, Tiered Rates: {meter.meter_rates}")
else:
print("No meters found in the rate card for the given query.")
except Exception as e:
print(f"An error occurred: {e}")
Debug
Known issues
breakingThe credential system was completely revamped in version 6.0.0. Older `azure.common.credentials` or `msrestazure.azure_active_directory` are no longer supported. You must now use classes from the `azure-identity` library (e.g., `DefaultAzureCredential`).fixMigrate your authentication code to use `azure-identity`. The `credentials` parameter in client constructors has also been renamed to `credential`.
affects: >=6.0.0
breakingThe `config` attribute on client objects was removed in version 6.0.0. Configuration options should now be passed directly as keyword arguments to the client's constructor.fixRemove `.config` access. Pass configuration like `enable_logging=True` directly to `CommerceManagementClient(credential, subscription_id, enable_logging=True)`.
affects: >=6.0.0
gotchaThis library (`azure-mgmt-commerce`) is for Azure Resource Manager (ARM) APIs. If you are working with older Azure Service Management (ASM) APIs, you need the `azure-servicemanagement-legacy` library instead. Most new development should use ARM.fixEnsure you understand whether you need ARM (this library) or ASM (`azure-servicemanagement-legacy`). For modern Azure environments, `azure-mgmt-commerce` is the correct choice.
affects: <6.0.0 (for legacy context), >=6.0.0 (current ARM)
breakingOperations that previously returned a `msrest.polling.LROPoller` now return `azure.core.polling.LROPoller` and are typically prefixed with `begin_` (e.g., `create_or_update` becomes `begin_create_or_update`). While `azure-mgmt-commerce` may not have many long-running operations, this is a general breaking change across Azure SDK management libraries in v6.x+.fixUpdate calls to long-running operations to use the `begin_` prefix and handle the `azure.core.polling.LROPoller` return type if applicable.
affects: >=6.0.0
Upgrade
Version history
6.0.1latest on PyPI · released May 15, 2026
Audit
Dependencies
azure-identityrequiredRequired for modern Azure Active Directory authentication in SDK v6.0.0+.