CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-azure-mgmt-consumption

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

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

usage-analytics.mddocs/

Usage and Analytics

Access detailed usage information, marketplace transactions, and consumption analytics for Azure resources. This module provides comprehensive usage reporting across various scopes and time periods.

Capabilities

Usage Details

Retrieve detailed usage information for Azure resources including cost, usage quantities, and metadata.

def list(
    scope: str,
    expand: str = None,
    filter: str = None,
    skiptoken: str = None,
    top: int = None,
    metric: str = None,
    **kwargs
) -> Iterable[UsageDetailsListResult]:
    """
    List usage details for the defined scope.
    
    Parameters:
    - scope: The scope for the usage details query (str)
    - expand: May be 'additionalInfo' or 'meterDetails' (str, optional)
    - filter: OData filter expression for the data (str, optional)
    - skiptoken: Token for pagination (str, optional)
    - top: Maximum number of items to return (int, optional)
    - metric: Type of metric to retrieve (str, optional)
    
    Returns:
    Iterable[UsageDetailsListResult]: Usage details collection
    """

Usage Example:

# Get usage details for subscription
scope = f"/subscriptions/{subscription_id}"
usage_details = client.usage_details.list(
    scope=scope,
    expand="meterDetails",
    top=100
)

for usage in usage_details:
    print(f"Resource: {usage.instance_name}")
    print(f"Cost: {usage.cost} {usage.billing_currency}")
    print(f"Date: {usage.date}")
    print(f"Meter: {usage.meter_details.meter_name}")

# Filter usage by date range
filter_expr = "properties/usageStart ge '2024-01-01' and properties/usageEnd le '2024-01-31'"
january_usage = client.usage_details.list(
    scope=scope,
    filter=filter_expr
)

Marketplace Transactions

Access marketplace usage data for third-party and marketplace services on Azure.

def list(
    scope: str,
    filter: str = None,
    top: int = None,
    skiptoken: str = None,
    **kwargs
) -> Iterable[MarketplacesListResult]:
    """
    List marketplace charges for the specified scope.
    
    Parameters:
    - scope: The scope for the marketplace query (str)
    - filter: OData filter expression (str, optional)
    - top: Maximum number of items to return (int, optional)
    - skiptoken: Token for pagination (str, optional)
    
    Returns:
    Iterable[MarketplacesListResult]: Marketplace transactions collection
    """

Usage Example:

# Get marketplace usage
marketplace_usage = client.marketplaces.list(
    scope=f"/subscriptions/{subscription_id}",
    top=50
)

for marketplace in marketplace_usage:
    print(f"Publisher: {marketplace.publisher_name}")
    print(f"Service: {marketplace.offer_name}")
    print(f"Cost: {marketplace.cost_in_billing_currency}")
    print(f"Billing Period: {marketplace.billing_period_name}")

Tags Analysis

Analyze cost allocation and usage patterns by resource tags.

def get(scope: str, **kwargs) -> Optional[TagsResult]:
    """
    Get all available tag keys for the defined scope.
    
    Parameters:
    - scope: The scope for the tags query (str)
    
    Returns:
    TagsResult: Collection of available tag keys
    """

Usage Example:

# Get available tags for cost analysis
tags_result = client.tags.get(scope=f"/subscriptions/{subscription_id}")

if tags_result and tags_result.tags:
    print("Available tags for cost allocation:")
    for tag in tags_result.tags:
        print(f"- {tag.key}: {len(tag.values)} values")

Types

Usage Detail Models

class UsageDetail:
    """Base class for usage detail information."""
    billing_account_id: str
    billing_account_name: str
    billing_period_start_date: datetime
    billing_period_end_date: datetime
    billing_profile_id: str
    billing_profile_name: str
    account_owner_id: str
    account_name: str
    subscription_id: str
    subscription_name: str
    date: datetime
    product: str
    part_number: str
    meter_id: str
    meter_details: MeterDetails
    quantity: float
    effective_price: float
    cost: float
    unit_price: float
    billing_currency: str
    resource_location: str
    consumed_service: str
    resource_id: str
    resource_name: str
    service_info1: str
    service_info2: str
    additional_info: str
    invoice_section: str
    cost_center: str
    resource_group: str
    reservation_id: str
    reservation_name: str
    product_order_id: str
    product_order_name: str
    offer_id: str
    is_azure_credit_eligible: bool
    term: str
    publisher_name: str
    publisher_type: str
    plan_name: str
    charge_type: str
    frequency: str

class LegacyUsageDetail(UsageDetail):
    """Legacy usage detail format."""
    instance_name: str
    instance_id: str
    instance_location: str
    currency: str
    usage_start: datetime
    usage_end: datetime
    
class ModernUsageDetail(UsageDetail):
    """Modern usage detail format."""
    cost_in_billing_currency: float
    cost_in_usd: float
    exchange_rate_pricing_to_billing: float
    exchange_rate_date: datetime
    invoice_id: str
    previous_invoice_id: str
    pricing_currency: str
    service_period_start_date: datetime
    service_period_end_date: datetime

Marketplace Models

class Marketplace:
    """Marketplace usage information."""
    billing_period_name: str
    cost_in_billing_currency: float
    cost_in_usd: float
    subscription_guid: str
    subscription_name: str
    meter_id: str
    meter_name: str
    meter_category: str
    meter_subcategory: str
    meter_region: str
    unit_of_measure: str
    instance_name: str
    instance_id: str
    instance_location: str
    currency: str
    consumed_quantity: float
    resource_rate: float
    offer_name: str
    resource_group: str
    order_number: str
    additional_properties: dict
    consumed_service: str
    service_info1: str
    service_info2: str
    tags: dict
    publisher_name: str
    plan_name: str
    is_recurring_charge: bool

Tag Models

class Tag:
    """Tag information for cost allocation."""
    key: str
    values: List[str]

class TagsResult:
    """Collection of available tag keys."""
    tags: List[Tag]
    next_link: str

Meter Detail Models

class MeterDetails:
    """Detailed meter information."""
    meter_name: str
    meter_category: str
    meter_subcategory: str
    unit_of_measure: str
    service_name: str
    service_tier: str
    meter_location: str
    total_included_quantity: float
    pre_tax_standard_rate: float

class MeterDetailsResponse:
    """Response containing meter details."""
    meter_details: List[MeterDetails]

List Result Models

class UsageDetailsListResult:
    """Container for usage details list response."""
    value: List[UsageDetail]
    next_link: str

class MarketplacesListResult:
    """Container for marketplace list response."""
    value: List[Marketplace]
    next_link: str

Enumeration Types

class Metrictype:
    """Metric types for usage queries."""
    ACTUAL_COST = "ActualCost"
    AMORTIZED_COST = "AmortizedCost"
    USAGE = "Usage"

class UsageDetailsKind:
    """Usage detail format types."""
    LEGACY = "legacy"
    MODERN = "modern"

Install with Tessl CLI

npx tessl i tessl/pypi-azure-mgmt-consumption

docs

aggregated-cost.md

budget-management.md

client-management.md

cost-analysis.md

credits-billing.md

index.md

operations.md

reservation-management.md

tags-operations.md

usage-analytics.md

tile.json