or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

aggregated-cost.mdbudget-management.mdclient-management.mdcost-analysis.mdcredits-billing.mdindex.mdoperations.mdreservation-management.mdtags-operations.mdusage-analytics.md
tile.json

tessl/pypi-azure-mgmt-consumption

Azure Consumption Management Client for accessing consumption resources, budgets, and usage analytics for Azure Enterprise Subscriptions

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/azure-mgmt-consumption@10.0.x

To install, run

npx @tessl/cli install tessl/pypi-azure-mgmt-consumption@10.0.0

index.mddocs/

Azure Consumption Management Client

A 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.

Package Information

  • Package Name: azure-mgmt-consumption
  • Language: Python
  • Installation: pip install azure-mgmt-consumption
  • Authentication: Azure credentials required

Core Imports

from azure.mgmt.consumption import ConsumptionManagementClient

Common authentication pattern:

from azure.identity import DefaultAzureCredential
from azure.mgmt.consumption import ConsumptionManagementClient

credential = DefaultAzureCredential()
client = ConsumptionManagementClient(credential, subscription_id)

Basic Usage

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}")

Architecture

The Azure Consumption Management Client follows the Azure SDK pattern with operation-specific classes accessed through the main client:

  • ConsumptionManagementClient: Main entry point providing access to all consumption operations
  • Operation Classes: Specialized classes for different resource types (budgets, usage, reservations, etc.)
  • Model Classes: Data structures representing Azure consumption resources and responses
  • Authentication Integration: Built-in support for Azure credential providers and token management
  • Pagination Support: Automatic handling of large result sets with iterator patterns

The client supports both synchronous and asynchronous operations (via the aio module) and provides comprehensive error handling with Azure-standard exceptions.

Capabilities

Client Initialization

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: ...

Client Management

Usage Details and Analytics

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]: ...

Usage and Analytics

Budget Management

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: ...

Budget Management

Reservation Management

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]: ...

Reservation Management

Cost Analysis and Reporting

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: ...

Cost Analysis

Credits and Billing

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: ...

Credits and Billing

Tags Management

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
    """

Tags Operations

Aggregated Cost Analysis

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
    """

Aggregated Cost

API Operations

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
    """

API Operations

Types

Core Client Types

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: ...

Common Response Types

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: ...

Enumeration Types

# 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: ...