CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-azure-mgmt-costmanagement

Microsoft Azure Cost Management Client Library for Python providing comprehensive access to cost analysis, billing data, budgets, alerts, exports, and recommendations.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

exports.mddocs/

Data Export Operations

Schedule and manage automated data exports for cost and usage data. Configure recurring exports to Azure storage accounts with custom formats, delivery schedules, and comprehensive cost data for analysis and integration with external systems.

Capabilities

Export Management

Create, update, and manage cost data export configurations with flexible scheduling and delivery options.

def list(scope: str, expand: str = None) -> ExportListResult:
    """
    List all exports for the specified scope.
    
    Args:
        scope (str): The scope to list exports for
        expand (str): Expand options for additional properties
    
    Returns:
        ExportListResult: Collection of export configurations
    """

def get(scope: str, export_name: str, expand: str = None) -> Export:
    """
    Get a specific export configuration by name.
    
    Args:
        scope (str): The scope containing the export
        export_name (str): Name of the export configuration
        expand (str): Expand options for additional properties
    
    Returns:
        Export: Export configuration details
    """

def create_or_update(scope: str, export_name: str, parameters: Export) -> Export:
    """
    Create or update an export configuration.
    
    Args:
        scope (str): The scope for the export
        export_name (str): Name for the export configuration
        parameters (Export): Export configuration details
    
    Returns:
        Export: Created or updated export configuration
    """

def delete(scope: str, export_name: str) -> None:
    """
    Delete an export configuration.
    
    Args:
        scope (str): The scope containing the export
        export_name (str): Name of the export to delete
    """

Export Execution

Execute exports immediately and track execution history for monitoring and troubleshooting.

def execute(scope: str, export_name: str) -> ExportRun:
    """
    Execute an export immediately.
    
    Args:
        scope (str): The scope containing the export
        export_name (str): Name of the export to execute
    
    Returns:
        ExportRun: Execution details and status
    """

def get_execution_history(scope: str, export_name: str) -> ExportExecutionListResult:
    """
    Get execution history for an export.
    
    Args:
        scope (str): The scope containing the export
        export_name (str): Name of the export
    
    Returns:
        ExportExecutionListResult: List of export execution records
    """

Usage Examples

Create Daily Cost Export

from azure.mgmt.costmanagement.models import (
    Export,
    ExportDefinition,
    ExportDeliveryInfo,
    ExportDeliveryDestination,
    ExportSchedule,
    ExportRecurrencePeriod,
    ExportDataset,
    ExportTimePeriod,
    RecurrenceType,
    FormatType,
    TimeframeType,
    GranularityType
)

# Configure export destination (Azure Storage)
delivery_destination = ExportDeliveryDestination(
    resource_id="/subscriptions/{sub-id}/resourceGroups/{rg}/providers/Microsoft.Storage/storageAccounts/{storage}",
    container="cost-exports",
    root_folder_path="daily-costs"
)

delivery_info = ExportDeliveryInfo(destination=delivery_destination)

# Configure export schedule (daily)
recurrence_period = ExportRecurrencePeriod(
    from_property="2024-01-01T00:00:00Z",
    to="2024-12-31T23:59:59Z"
)

schedule = ExportSchedule(
    status="Active",
    recurrence=RecurrenceType.DAILY,
    recurrence_period=recurrence_period
)

# Configure export dataset
dataset = ExportDataset(
    granularity=GranularityType.DAILY
)

# Configure export definition
export_definition = ExportDefinition(
    type="ActualCost",
    timeframe=TimeframeType.MONTH_TO_DATE,
    dataset=dataset
)

# Create export
export_config = Export()
export_config.properties = ExportProperties(
    format=FormatType.CSV,
    delivery_info=delivery_info,
    schedule=schedule,
    definition=export_definition
)

scope = "/subscriptions/{subscription-id}"
created_export = client.exports.create_or_update(
    scope=scope,
    export_name="daily-cost-export",
    parameters=export_config
)

print(f"Created export: {created_export.name}")

List and Monitor Exports

# List all exports for subscription
exports = client.exports.list(scope)

print(f"Found {len(exports.value)} exports:")
for export in exports.value:
    props = export.properties
    print(f"  Name: {export.name}")
    print(f"  Type: {props.definition.type}")
    print(f"  Schedule: {props.schedule.recurrence}")
    print(f"  Status: {props.schedule.status}")
    print(f"  Next Run: {props.next_run_time_estimate}")
    print("  ---")

Execute Export Immediately

# Execute an export on-demand
export_run = client.exports.execute(scope, "daily-cost-export")

print(f"Export execution started:")
print(f"  Status: {export_run.properties.status}")
print(f"  Execution Type: {export_run.properties.execution_type}")
print(f"  Run Settings: {export_run.properties.run_settings}")

Monitor Export Execution History

# Get execution history
execution_history = client.exports.get_execution_history(scope, "daily-cost-export")

print(f"Export execution history ({len(execution_history.value)} runs):")
for run in execution_history.value:
    props = run.properties
    print(f"  Run Time: {props.execution_time}")
    print(f"  Status: {props.status}")
    print(f"  Processing Start: {props.processing_start_time}")
    print(f"  Processing End: {props.processing_end_time}")
    if props.file_name:
        print(f"  File: {props.file_name}")
    if props.error:
        print(f"  Error: {props.error}")
    print("  ---")

Create Monthly Amortized Cost Export

# Monthly export with amortized costs
monthly_dataset = ExportDataset(
    granularity=GranularityType.MONTHLY
)

monthly_schedule = ExportSchedule(
    status="Active", 
    recurrence=RecurrenceType.MONTHLY,
    recurrence_period=ExportRecurrencePeriod(
        from_property="2024-01-01T00:00:00Z"
    )
)

monthly_export_def = ExportDefinition(
    type="AmortizedCost",
    timeframe=TimeframeType.THE_LAST_MONTH,
    dataset=monthly_dataset
)

monthly_export = Export()
monthly_export.properties = ExportProperties(
    format=FormatType.CSV,
    delivery_info=delivery_info,
    schedule=monthly_schedule,
    definition=monthly_export_def
)

monthly_created = client.exports.create_or_update(
    scope=scope,
    export_name="monthly-amortized-export", 
    parameters=monthly_export
)

Data Models

Export Configuration Models

class Export:
    id: str
    name: str
    type: str
    properties: ExportProperties

class ExportProperties:
    format: FormatType
    delivery_info: ExportDeliveryInfo
    definition: ExportDefinition
    run_history: CommonExportProperties
    next_run_time_estimate: str
    schedule: ExportSchedule

class ExportDefinition:
    type: str
    timeframe: TimeframeType
    time_period: ExportTimePeriod
    dataset: ExportDataset

class ExportDataset:
    granularity: GranularityType
    configuration: ExportDatasetConfiguration

class ExportDeliveryInfo:
    destination: ExportDeliveryDestination

class ExportDeliveryDestination:
    resource_id: str
    container: str
    root_folder_path: str

class ExportSchedule:
    status: str
    recurrence: RecurrenceType
    recurrence_period: ExportRecurrencePeriod

class ExportRecurrencePeriod:
    from_property: str
    to: str

Export Execution Models

class ExportRun:
    id: str
    name: str
    type: str
    properties: ExportRunProperties

class ExportRunProperties:
    status: ExecutionStatus
    error: ErrorDetails
    execution_type: ExecutionType
    file_name: str
    processing_start_time: str
    processing_end_time: str
    execution_time: str
    run_settings: CommonExportProperties

class ExportListResult:
    value: List[Export]

class ExportExecutionListResult:
    value: List[ExportRun]

class CommonExportProperties:
    partition_data: bool
    data_overwrite_behavior: str

Export Enumerations

class FormatType(str, Enum):
    CSV = "Csv"

class RecurrenceType(str, Enum):
    DAILY = "Daily"
    WEEKLY = "Weekly"
    MONTHLY = "Monthly"
    ANNUALLY = "Annually"

class ExecutionStatus(str, Enum):
    QUEUED = "Queued"
    IN_PROGRESS = "InProgress" 
    COMPLETED = "Completed"
    FAILED = "Failed"
    TIMEOUT = "Timeout"
    NEW_DATA_NOT_AVAILABLE = "NewDataNotAvailable"
    DATA_NOT_AVAILABLE = "DataNotAvailable"

class ExecutionType(str, Enum):
    ON_DEMAND = "OnDemand"
    SCHEDULED = "Scheduled"

class ExportType(str, Enum):
    USAGE = "Usage"
    ACTUAL_COST = "ActualCost"
    AMORTIZED_COST = "AmortizedCost"

This module provides comprehensive data export capabilities for automating cost data delivery to external storage systems for analysis, reporting, and integration workflows.

Install with Tessl CLI

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

docs

alerts.md

benefits.md

dimensions.md

exports.md

index.md

price-sheet.md

query-forecast.md

reports.md

scheduled-actions.md

views.md

tile.json