Azure Consumption Management Client for accessing consumption resources, budgets, and usage analytics for Azure Enterprise Subscriptions
npx @tessl/cli install tessl/pypi-azure-mgmt-consumption@10.0.0A comprehensive Python client library that enables programmatic access and management of Azure consumption resources for Enterprise Subscriptions. The library provides complete cost monitoring, budgeting, and optimization capabilities through Azure Resource Manager APIs.
pip install azure-mgmt-consumptionfrom azure.mgmt.consumption import ConsumptionManagementClientCommon authentication pattern:
from azure.identity import DefaultAzureCredential
from azure.mgmt.consumption import ConsumptionManagementClient
credential = DefaultAzureCredential()
client = ConsumptionManagementClient(credential, subscription_id)from azure.identity import DefaultAzureCredential
from azure.mgmt.consumption import ConsumptionManagementClient
# Authenticate and create client
credential = DefaultAzureCredential()
subscription_id = "your-subscription-id"
client = ConsumptionManagementClient(credential, subscription_id)
# Get usage details for current billing period
scope = f"/subscriptions/{subscription_id}"
usage_details = client.usage_details.list(scope=scope)
for usage in usage_details:
print(f"Resource: {usage.instance_name}")
print(f"Cost: {usage.cost} {usage.billing_currency}")
print(f"Usage Date: {usage.date}")
# Create a budget
budget_name = "monthly-budget-2024"
budget_scope = f"/subscriptions/{subscription_id}"
budget = {
"category": "Cost",
"amount": 1000.0,
"time_grain": "Monthly",
"time_period": {
"start_date": "2024-01-01T00:00:00Z"
},
"notifications": {
"actual_80": {
"enabled": True,
"operator": "GreaterThan",
"threshold": 80,
"contact_emails": ["admin@company.com"]
}
}
}
created_budget = client.budgets.create_or_update(budget_scope, budget_name, budget)
print(f"Budget created: {created_budget.name}")The Azure Consumption Management Client follows the Azure SDK pattern with operation-specific classes accessed through the main client:
The client supports both synchronous and asynchronous operations (via the aio module) and provides comprehensive error handling with Azure-standard exceptions.
Main client class initialization and configuration for accessing Azure consumption management APIs.
class ConsumptionManagementClient:
def __init__(
self,
credential: TokenCredential,
subscription_id: str,
base_url: str = "https://management.azure.com",
**kwargs
) -> None: ...Access detailed usage information, marketplace transactions, and consumption analytics for Azure resources across various scopes and time periods.
# Usage details operations
def list(
scope: str,
expand: str = None,
filter: str = None,
skiptoken: str = None,
top: int = None,
metric: str = None
) -> Iterable[UsageDetailsListResult]: ...Create, update, and manage budgets with notifications, alerts, and spending controls for cost management across different Azure scopes.
# Budget operations
def list(scope: str) -> Iterable[BudgetsListResult]: ...
def get(scope: str, budget_name: str) -> Budget: ...
def create_or_update(scope: str, budget_name: str, parameters: Budget) -> Budget: ...
def delete(scope: str, budget_name: str) -> None: ...Access reservation summaries, details, recommendations, and transaction history for cost optimization through Azure Reserved Instances.
# Reservation summaries
def list(
resource_scope: str,
grain: str,
start_date: str = None,
end_date: str = None,
filter: str = None,
reservation_id: str = None,
reservation_order_id: str = None
) -> Iterable[ReservationSummariesListResult]: ...
# Reservation recommendations
def list(resource_scope: str, filter: str = None) -> Iterable[ReservationRecommendationsListResult]: ...Analyze charges, balances, aggregated costs, and marketplace usage for comprehensive financial reporting and cost allocation.
# Charges operations
def list(
scope: str,
start_date: str = None,
end_date: str = None,
filter: str = None,
apply: str = None
) -> ChargesListResult: ...
# Balance operations
def get_by_billing_account(billing_account_id: str) -> Balance: ...Manage Azure credits, lots, events, and price sheet information for Enterprise Agreement and Microsoft Customer Agreement billing accounts.
# Credits operations
def get(billing_account_id: str, billing_profile_id: str) -> CreditSummary: ...
# Price sheet operations
def get(expand: str = None, skiptoken: str = None, top: int = None) -> PriceSheetResult: ...Retrieve all available tag keys for cost allocation and management across various Azure scopes including subscriptions, billing accounts, and management groups.
def get(scope: str, **kwargs) -> Optional[TagsResult]:
"""
Get all available tag keys for the defined scope.
Parameters:
- scope: The scope for tag operations (str)
Returns:
Optional[TagsResult]: Available tag keys and values
"""Access aggregated cost data for management groups across current and historical billing periods for comprehensive cost oversight.
def get_by_management_group(
management_group_id: str,
filter: str = None,
**kwargs
) -> ManagementGroupAggregatedCostResult:
"""
Get aggregate cost for a management group and child groups.
Parameters:
- management_group_id: Azure Management Group ID (str)
- filter: Optional filter expression (str)
Returns:
ManagementGroupAggregatedCostResult: Aggregated cost data
"""
def get_for_billing_period_by_management_group(
management_group_id: str,
billing_period_name: str,
**kwargs
) -> ManagementGroupAggregatedCostResult:
"""
Get aggregate cost for specific billing period.
Parameters:
- management_group_id: Azure Management Group ID (str)
- billing_period_name: Billing period name (str)
Returns:
ManagementGroupAggregatedCostResult: Historical aggregated cost data
"""List all available consumption REST API operations for service discovery and capability exploration.
def list(**kwargs) -> Iterable[OperationListResult]:
"""
List all available consumption REST API operations.
Returns:
Iterable[OperationListResult]: Available API operations
"""from azure.core.credentials import TokenCredential
class ConsumptionManagementClient:
def __init__(
self,
credential: TokenCredential,
subscription_id: str,
base_url: str = "https://management.azure.com",
**kwargs
) -> None: ...
def close(self) -> None: ...
def __enter__(self) -> ConsumptionManagementClient: ...
def __exit__(self, *exc_details) -> None: ...from typing import Iterable, Optional
# List result containers
class UsageDetailsListResult: ...
class BudgetsListResult: ...
class ChargesListResult: ...
class MarketplacesListResult: ...
class ReservationSummariesListResult: ...
class ReservationDetailsListResult: ...
class ReservationRecommendationsListResult: ...
class ReservationTransactionsListResult: ...
class OperationListResult: ...# Billing and time-related enums
class BillingFrequency: ...
class TimeGrainType: ...
class Datagrain: ...
class Term: ...
# Budget and operator enums
class BudgetOperatorType: ...
class OperatorType: ...
class ThresholdType: ...
class CategoryType: ...
# Reservation and pricing enums
class ReservationRecommendationKind: ...
class PricingModelType: ...
class LookBackPeriod: ...
class Scope: ...
# Status and metric enums
class Status: ...
class Metrictype: ...
class UsageDetailsKind: ...
class ChargeSummaryKind: ...
class EventType: ...
class LotSource: ...
class CultureCode: ...
# Operations response types
class TagsResult: ...
class ManagementGroupAggregatedCostResult: ...
class OperationListResult: ...
class PriceSheetResult: ...