Azure Consumption Management Client for accessing consumption resources, budgets, and usage analytics for Azure Enterprise Subscriptions
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Analyze charges, balances, aggregated costs, and marketplace usage for comprehensive financial reporting and cost allocation. This module provides detailed cost breakdowns and aggregation capabilities.
Access charge information for different billing periods and scopes with filtering and aggregation options.
def list(
scope: str,
start_date: str = None,
end_date: str = None,
filter: str = None,
apply: str = None,
**kwargs
) -> ChargesListResult:
"""
List charges for the specified scope and time period.
Parameters:
- scope: The scope for the charges query (str)
- start_date: Start date for the query (str, optional)
- end_date: End date for the query (str, optional)
- filter: OData filter expression (str, optional)
- apply: OData apply expression for aggregation (str, optional)
Returns:
ChargesListResult: Charges information
"""Get account balance information for billing accounts and billing periods.
def get_by_billing_account(billing_account_id: str, **kwargs) -> Balance:
"""
Get balance information for a billing account.
Parameters:
- billing_account_id: The billing account ID (str)
Returns:
Balance: Account balance information
"""
def get_for_billing_period_by_billing_account(
billing_account_id: str,
billing_period_name: str,
**kwargs
) -> Balance:
"""
Get balance information for a specific billing period.
Parameters:
- billing_account_id: The billing account ID (str)
- billing_period_name: The billing period name (str)
Returns:
Balance: Account balance for the billing period
"""Analyze aggregated costs for management groups with hierarchical cost rollup.
def get_by_management_group(
management_group_id: str,
filter: str = None,
**kwargs
) -> ManagementGroupAggregatedCostResult:
"""
Get aggregated cost for a management group and all child groups.
Parameters:
- management_group_id: The management group ID (str)
- filter: OData filter expression (str, optional)
Returns:
ManagementGroupAggregatedCostResult: Aggregated cost information
"""
def get_for_billing_period_by_management_group(
management_group_id: str,
billing_period_name: str,
**kwargs
) -> ManagementGroupAggregatedCostResult:
"""
Get aggregated cost for a management group for a specific billing period.
Parameters:
- management_group_id: The management group ID (str)
- billing_period_name: The billing period name (str)
Returns:
ManagementGroupAggregatedCostResult: Aggregated cost for billing period
"""Usage Example:
# Analyze charges for current month
from datetime import datetime, timedelta
scope = f"/subscriptions/{subscription_id}"
start_date = datetime.now().replace(day=1).strftime("%Y-%m-%d")
end_date = datetime.now().strftime("%Y-%m-%d")
charges = client.charges.list(
scope=scope,
start_date=start_date,
end_date=end_date
)
print("Charge Summary:")
for charge in charges.value:
print(f"Charge Type: {charge.kind}")
if hasattr(charge, 'azure_charges'):
print(f"Azure Charges: ${charge.azure_charges}")
if hasattr(charge, 'marketplace_charges'):
print(f"Marketplace Charges: ${charge.marketplace_charges}")
# Get balance information for EA billing account
billing_account_id = "your-billing-account-id"
balance = client.balances.get_by_billing_account(billing_account_id)
print(f"Current Balance: ${balance.new_purchases}")
print(f"Adjustments: ${balance.adjustments}")
print(f"Beginning Balance: ${balance.beginning_balance}")
print(f"Ending Balance: ${balance.ending_balance}")
# Get aggregated costs for management group
management_group_id = "your-management-group-id"
aggregated_cost = client.aggregated_cost.get_by_management_group(
management_group_id=management_group_id,
filter="properties/usageStart ge '2024-01-01'"
)
print(f"Total Cost: ${aggregated_cost.azure_charges}")
print(f"Billing Period: {aggregated_cost.billing_period}")
print(f"Children Count: {len(aggregated_cost.children)}")
# Analyze charges with grouping
charges_grouped = client.charges.list(
scope=scope,
apply="groupby((properties/chargeType))"
)class ChargeSummary:
"""Base class for charge summaries."""
id: str
name: str
type: str
etag: str
kind: str
class LegacyChargeSummary(ChargeSummary):
"""Legacy format charge summary."""
billing_period_name: str
usage_start: datetime
usage_end: datetime
azure_charges: float
marketplace_charges: float
billing_account_id: str
billing_account_name: str
billing_profile_id: str
billing_profile_name: str
invoice_section_id: str
invoice_section_name: str
customer_tenant_id: str
customer_name: str
is_invoice_ready: bool
class ModernChargeSummary(ChargeSummary):
"""Modern format charge summary."""
azure_charges: float
marketplace_charges: float
billing_account_id: str
billing_period_name: str
usage_start: datetime
usage_end: datetimeclass Balance:
"""Account balance information."""
id: str
name: str
type: str
etag: str
beginning_balance: float
ending_balance: float
new_purchases: float
adjustments: float
utilized: float
service_overage: float
charges_billed_separately: float
total_overage: float
total_usage: float
azure_marketplace_service_charges: float
billing_frequency: str
price_hidden: bool
new_purchases_details: List[BalancePropertiesNewPurchasesDetailsItem]
adjustment_details: List[BalancePropertiesAdjustmentDetailsItem]
class BalancePropertiesNewPurchasesDetailsItem:
"""New purchases detail item."""
name: str
value: float
class BalancePropertiesAdjustmentDetailsItem:
"""Adjustment detail item."""
name: str
value: floatclass ManagementGroupAggregatedCostResult:
"""Aggregated cost result for management group."""
id: str
name: str
type: str
etag: str
management_group_id: str
azure_charges: float
marketplace_charges: float
billing_period: str
usage_start: datetime
usage_end: datetime
children: List[ManagementGroupAggregatedCostResult]
included_subscriptions: List[str]
excluded_subscriptions: List[str]class ChargesListResult:
"""Container for charges list response."""
value: List[ChargeSummary]
next_link: strclass ChargeSummaryKind:
"""Charge summary format types."""
LEGACY = "legacy"
MODERN = "modern"
class BillingFrequency:
"""Billing frequency options."""
MONTH = "Month"
QUARTER = "Quarter"
YEAR = "Year"Install with Tessl CLI
npx tessl i tessl/pypi-azure-mgmt-consumption