Registry / azure / azure-mgmt-costmanagement

azure-mgmt-costmanagement

JSON →
library5.0.0pypypi✓ verified 20d ago

The Microsoft Azure Cost Management Client Library for Python allows developers to manage Azure cost and usage data programmatically. It provides access to features like querying cost data, managing budgets, and working with dimensions and exports. Currently at version 4.0.1, it follows the Azure SDK release cadence, with updates often tied to new API versions and general SDK guidelines.

pip install azure-mgmt-costmanagement azure-identity
INSTALL
IMPORT
SIG · AZURE-MGMT-COSTMAN
A
azure-mgmt-costmanagement
azurepythonv5.0.0
Install
3.8s avg
Import
649ms
Disk
45MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v5.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.690s · 45.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.8s · import 0.608s · 46MB
45MB installed
● package 45MB
Code
Verified usage

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

CostManagementClient
from azure.mgmt.costmanagement import CostManagementClient
DefaultAzureCredential
from azure.identity import DefaultAzureCredential
Required for authentication with Azure services.

This quickstart demonstrates how to authenticate with Azure using `DefaultAzureCredential` and then list existing budgets within a specified Azure subscription using the `CostManagementClient`. Ensure you have the `AZURE_SUBSCRIPTION_ID` environment variable set, and your Azure credentials configured (e.g., via `az login` or environment variables like `AZURE_CLIENT_ID`, `AZURE_CLIENT_SECRET`, `AZURE_TENANT_ID`).

import os from azure.identity import DefaultAzureCredential from azure.mgmt.costmanagement import CostManagementClient # Set your Azure Subscription ID from environment variables 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.") else: try: # Authenticate using DefaultAzureCredential (looks for env vars, managed identity, etc.) credential = DefaultAzureCredential() # Create a CostManagementClient client = CostManagementClient(credential, subscription_id) # Example: List budgets for the subscription print(f"Listing budgets for subscription: {subscription_id}") scope = f"subscriptions/{subscription_id}" budgets = client.budgets.list(scope=scope) found_budgets = False for budget in budgets: print(f" Budget Name: {budget.name}, Amount: {budget.amount} {budget.currency}") found_budgets = True if not found_budgets: print(" No budgets found for this subscription.") except Exception as e: print(f"An error occurred: {e}") print("Ensure you have set up Azure credentials (e.g., AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, AZURE_TENANT_ID) or are logged in via `az login`.")
Debug
Known issues
breakingVersion 3.0.0 introduced a complete rewrite of the SDK following new Azure SDK guidelines. The main client class was renamed to `CostManagementClient`, and all models and operations moved under `azure.mgmt.costmanagement.models` and `azure.mgmt.costmanagement.operations`. Asynchronous operations are now available via `azure.mgmt.costmanagement.aio`.
fix
Update import paths and client instantiation logic. Refer to the official Azure SDK documentation for the new API surface.
affects: >=3.0.0
breakingIn version 4.0.0, the `QueryDefinition` model had two new required parameters added: `time_period` and `type`. Calls using `QueryDefinition` without these parameters will fail.
fix
Ensure that `time_period` and `type` are always provided when constructing `QueryDefinition` objects for queries.
affects: >=4.0.0
gotchaAzure SDK management libraries like `azure-mgmt-costmanagement` require separate installation of an authentication library (e.g., `azure-identity`) for convenient credential management. While `azure-mgmt-costmanagement` does not directly depend on `azure-identity` via `pip` requirements, it is essential for practical use.
fix
Always install `azure-identity` alongside any `azure-mgmt-*` library: `pip install azure-mgmt-costmanagement azure-identity`.
affects: All versions
gotchaThe Cost Management API often uses 'scopes' to define the context for operations (e.g., subscription, resource group, management group). Incorrectly formatted scopes or scopes without appropriate permissions will result in authorization errors.
fix
Ensure the scope string is correctly formatted (e.g., `subscriptions/{subscriptionId}`, `subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}`) and the authenticated principal has the necessary 'Cost Management Contributor' or similar role.
affects: All versions
Upgrade
Version history
5.0.0latest on PyPI · released Jul 8, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
42 hits · last 30 days
node
36
OpenAI (training)
1
Resources