{"id":3413,"library":"azure-mgmt-consumption","title":"Azure Management Consumption Client Library for Python","description":"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.","status":"active","version":"10.0.0","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python","tags":["azure","cloud","consumption","cost management","billing","management"],"install":[{"cmd":"pip install azure-mgmt-consumption azure-identity","lang":"bash","label":"Install package with identity"}],"dependencies":[{"reason":"Required for modern Azure SDK authentication.","package":"azure-identity","optional":false},{"reason":"Provides core functionalities like HTTP pipeline, exceptions, and polling mechanisms for Azure SDKs.","package":"azure-core","optional":false}],"imports":[{"symbol":"ConsumptionManagementClient","correct":"from azure.mgmt.consumption import ConsumptionManagementClient"},{"note":"Old credential classes like ServicePrincipalCredentials are no longer supported in modern Azure SDKs. Use classes from azure-identity.","wrong":"from msrestazure.azure_active_directory import ServicePrincipalCredentials","symbol":"DefaultAzureCredential","correct":"from azure.identity import DefaultAzureCredential"},{"note":"Use the 'aio' namespace for the asynchronous client.","symbol":"aio.ConsumptionManagementClient","correct":"from azure.mgmt.consumption.aio import ConsumptionManagementClient"}],"quickstart":{"code":"import os\nfrom azure.identity import DefaultAzureCredential\nfrom azure.mgmt.consumption import ConsumptionManagementClient\n\n# Set your Azure Subscription ID as an environment variable or replace directly\n# For example: export AZURE_SUBSCRIPTION_ID=\"<your-subscription-id>\"\nsubscription_id = os.environ.get(\"AZURE_SUBSCRIPTION_ID\", \"\")\n\nif not subscription_id:\n    raise ValueError(\"AZURE_SUBSCRIPTION_ID environment variable not set.\")\n\n# Authenticate using DefaultAzureCredential\n# This will try several authentication methods, including environment variables,\n# managed identity, Visual Studio Code, Azure CLI, etc.\ncredential = DefaultAzureCredential()\n\n# Create a client for the Azure Consumption Management\nclient = ConsumptionManagementClient(credential, subscription_id)\n\nprint(f\"Listing usage details for subscription: {subscription_id}\")\n\n# List usage details for the current subscription\n# 'scope' is typically '/subscriptions/{subscriptionId}' or '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}'\n# For simplicity, we'll use the subscription scope.\nscope = f\"/subscriptions/{subscription_id}\"\n\n# Iterate through the usage details (adjust filter if needed)\n# Note: For MCA (Microsoft Customer Agreement) subscriptions, historical data might be limited.\n# See warnings for more details.\nfor 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):\n    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}\")\n\nprint(\"Successfully listed some usage details.\")","lang":"python","description":"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."},"warnings":[{"fix":"Migrate authentication code to use `azure-identity`. Example: `from azure.identity import DefaultAzureCredential; credential = DefaultAzureCredential(); client = ConsumptionManagementClient(credential, subscription_id)`.","message":"Credential 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`.","severity":"breaking","affected_versions":">=8.0.0b1"},{"fix":"Update all calls to model constructors or methods to use `key=value` syntax instead of positional arguments.","message":"Model 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.","severity":"breaking","affected_versions":">=3.0.0"},{"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.","message":"Version 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.","severity":"breaking","affected_versions":"10.0.0"},{"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.","message":"When 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.","severity":"gotcha","affected_versions":"All versions"},{"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`).","message":"Asynchronous 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.","severity":"gotcha","affected_versions":">=8.0.0b1"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}