Registry / azure / azure-mgmt-consumption

azure-mgmt-consumption

JSON →
library11.0.0pypypi✓ verified 23d ago

This is the Microsoft Azure Consumption Client Library. It allows programmatic management of consumption resources for Azure Enterprise Subscriptions, providing APIs to retrieve usage details, budgets, reservations, and other cost management data. The library is currently at version 10.0.0 and receives regular updates as part of the broader Azure SDK for Python.

pip install azure-mgmt-consumption azure-identity
INSTALL
IMPORT
SIG · AZURE-MGMT-CONSUMP
A
azure-mgmt-consumption
azurepythonv11.0.0
Install
3.8s avg
Import
649ms
Disk
44MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v11.0.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 0.670s · 44.5MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.8s · import 0.628s · 45MB
44MB installed
● package 44MB
Code
Verified usage

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

ConsumptionManagementClient
from azure.mgmt.consumption import ConsumptionManagementClient
DefaultAzureCredential
from azure.identity import DefaultAzureCredential
from msrestazure.azure_active_directory import ServicePrincipalCredentials
Old credential classes like ServicePrincipalCredentials are no longer supported in modern Azure SDKs. Use classes from azure-identity.
aio.ConsumptionManagementClient
from azure.mgmt.consumption.aio import ConsumptionManagementClient
Use the 'aio' namespace for the asynchronous client.

This quickstart initializes the ConsumptionManagementClient using `DefaultAzureCredential` and lists the first 10 usage details for a specified subscription. Ensure `AZURE_SUBSCRIPTION_ID` and other Azure authentication environment variables (e.g., `AZURE_CLIENT_ID`, `AZURE_CLIENT_SECRET`, `AZURE_TENANT_ID`) are set for `DefaultAzureCredential` to work. The example includes a basic filter for a specific month.

import os from azure.identity import DefaultAzureCredential from azure.mgmt.consumption import ConsumptionManagementClient # Set your Azure Subscription ID as an environment variable or replace directly # For example: export AZURE_SUBSCRIPTION_ID="<your-subscription-id>" subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "") if not subscription_id: raise ValueError("AZURE_SUBSCRIPTION_ID environment variable not set.") # Authenticate using DefaultAzureCredential # This will try several authentication methods, including environment variables, # managed identity, Visual Studio Code, Azure CLI, etc. credential = DefaultAzureCredential() # Create a client for the Azure Consumption Management client = ConsumptionManagementClient(credential, subscription_id) print(f"Listing usage details for subscription: {subscription_id}") # List usage details for the current subscription # 'scope' is typically '/subscriptions/{subscriptionId}' or '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' # For simplicity, we'll use the subscription scope. scope = f"/subscriptions/{subscription_id}" # Iterate through the usage details (adjust filter if needed) # Note: For MCA (Microsoft Customer Agreement) subscriptions, historical data might be limited. # See warnings for more details. for usage_detail in client.usage_details.list(scope=scope, expand="meterDetails,additionalProperties", filter="properties/usageEnd ge '2026-03-01' and properties/usageEnd le '2026-03-31'", top=10): print(f" Resource: {usage_detail.resource_id.split('/')[-1]} | Date: {usage_detail.usage_start} - {usage_detail.usage_end} | Cost: {usage_detail.pretax_cost} {usage_detail.currency}") print("Successfully listed some usage details.")
Debug
Known issues
breakingCredential system has been completely revamped. `azure.common.credentials` or `msrestazure.azure_active_directory` instances are no longer supported. Use classes from `azure-identity` (e.g., `DefaultAzureCredential`). The `credentials` parameter on client constructors has been renamed to `credential`.
fix
Migrate authentication code to use `azure-identity`. Example: `from azure.identity import DefaultAzureCredential; credential = DefaultAzureCredential(); client = ConsumptionManagementClient(credential, subscription_id)`.
affects: >=8.0.0b1
breakingModel signatures now use only keyword-argument syntax. All positional arguments for model instantiation must be rewritten as keyword arguments. This is a general Azure SDK change.
fix
Update all calls to model constructors or methods to use `key=value` syntax instead of positional arguments.
affects: >=3.0.0
breakingVersion 10.0.0 introduced several breaking changes including: `BudgetFilter` no longer has parameter `not_property`. Operations like `ReservationRecommendationDetailsOperations.get`, `ReservationRecommendationsOperations.list`, `ReservationsDetailsOperations.list`, and `ReservationsSummariesOperations.list` now have a `resource_scope` parameter and in some cases no longer have the `scope` parameter.
fix
Review the specific operation signatures in the documentation for version 10.0.0 and adjust parameter usage accordingly, especially for filtering and scoping reservations and budgets.
affects: 10.0.0
gotchaWhen listing usage details for Microsoft Customer Agreement (MCA) Pay-as-you-go subscriptions, users may find historical data restricted to only the current billing month, even with appropriate 'Reader' roles. This might be an API limitation for certain subscription types.
fix
For MCA subscriptions, try using the `billingPeriodName` parameter instead of date-based filters or consult Azure Support to understand historical data access limitations for your specific subscription type.
affects: All versions
gotchaAsynchronous clients are available in the `aio` namespace (e.g., `azure.mgmt.consumption.aio.ConsumptionManagementClient`). Using these requires an `async`/`await` pattern and an async credential.
fix
Import from `azure.mgmt.consumption.aio` and ensure your application code correctly uses `async`/`await` with an `AsyncTokenCredential` (e.g., `AsyncDefaultAzureCredential` from `azure.identity.aio`).
affects: >=8.0.0b1
Upgrade
Version history
11.0.0latest on PyPI · released Jul 20, 2026
Audit
Dependencies
azure-identityrequiredRequired for modern Azure SDK authentication.
azure-corerequiredProvides core functionalities like HTTP pipeline, exceptions, and polling mechanisms for Azure SDKs.
Agent activity
38 hits · last 30 days
node
30
OpenAI (training)
2
Resources
azure-mgmt-consumption — pip install azure-mgmt-consumption · libregistry