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
Create, update, and manage budgets with notifications, alerts, and spending controls for comprehensive cost management across different Azure scopes. This module provides full CRUD operations for budget lifecycle management.
Retrieve all budgets for a specified scope.
def list(scope: str, **kwargs) -> Iterable[BudgetsListResult]:
"""
List all budgets for the defined scope.
Parameters:
- scope: The scope for the budget query (str)
Returns:
Iterable[BudgetsListResult]: Collection of budgets
"""Get a specific budget by name and scope.
def get(scope: str, budget_name: str, **kwargs) -> Budget:
"""
Get a specific budget by scope and budget name.
Parameters:
- scope: The scope for the budget (str)
- budget_name: Name of the budget (str)
Returns:
Budget: The budget details
"""Create new budgets or update existing ones with comprehensive configuration options.
def create_or_update(
scope: str,
budget_name: str,
parameters: Budget,
**kwargs
) -> Budget:
"""
Create or update a budget with notification settings.
Parameters:
- scope: The scope for the budget (str)
- budget_name: Name of the budget (str)
- parameters: Budget configuration (Budget)
Returns:
Budget: The created or updated budget
"""Remove budgets that are no longer needed.
def delete(scope: str, budget_name: str, **kwargs) -> None:
"""
Delete a specific budget.
Parameters:
- scope: The scope for the budget (str)
- budget_name: Name of the budget to delete (str)
"""Usage Example:
# Create a monthly budget with notifications
scope = f"/subscriptions/{subscription_id}"
budget_name = "monthly-cost-budget"
# Define budget configuration
from azure.mgmt.consumption.models import (
Budget, BudgetTimePeriod, CurrentSpend, ForecastSpend, Notification
)
budget_config = Budget(
category="Cost",
amount=1000.0,
time_grain="Monthly",
time_period=BudgetTimePeriod(
start_date="2024-01-01T00:00:00Z"
),
current_spend=CurrentSpend(amount=0.0, unit="USD"),
notifications={
"actual_50": Notification(
enabled=True,
operator="GreaterThan",
threshold=50,
contact_emails=["finance@company.com"],
contact_groups=[],
contact_roles=["Owner"]
),
"actual_80": Notification(
enabled=True,
operator="GreaterThan",
threshold=80,
contact_emails=["finance@company.com", "admin@company.com"],
contact_groups=[],
contact_roles=["Owner", "Contributor"]
),
"forecast_100": Notification(
enabled=True,
operator="GreaterThan",
threshold=100,
contact_emails=["finance@company.com"],
contact_groups=[],
contact_roles=["Owner"],
threshold_type="Forecasted"
)
}
)
# Create the budget
created_budget = client.budgets.create_or_update(
scope=scope,
budget_name=budget_name,
parameters=budget_config
)
print(f"Budget created: {created_budget.name}")
print(f"Amount: {created_budget.amount} {created_budget.current_spend.unit}")
# List all budgets
budgets = client.budgets.list(scope=scope)
for budget in budgets:
print(f"Budget: {budget.name} - {budget.amount}")
print(f"Current spend: {budget.current_spend.amount}")
if budget.forecast_spend:
print(f"Forecasted spend: {budget.forecast_spend.amount}")
# Update budget amount
budget_config.amount = 1500.0
updated_budget = client.budgets.create_or_update(
scope=scope,
budget_name=budget_name,
parameters=budget_config
)
# Get specific budget
budget = client.budgets.get(scope=scope, budget_name=budget_name)
print(f"Retrieved budget: {budget.name}")
# Delete budget when no longer needed
client.budgets.delete(scope=scope, budget_name=budget_name)
print("Budget deleted")class Budget:
"""Budget configuration and status."""
id: str
name: str
type: str
etag: str
category: str # "Cost" or "Usage"
amount: float
time_grain: str # "Monthly", "Quarterly", "Annually", "BillingMonth", "BillingQuarter", "BillingAnnual"
time_period: BudgetTimePeriod
filter: BudgetFilter
current_spend: CurrentSpend
forecast_spend: ForecastSpend
notifications: Dict[str, Notification]
class BudgetTimePeriod:
"""Time period configuration for budget."""
start_date: str # ISO 8601 datetime
end_date: str # ISO 8601 datetime (optional)
class CurrentSpend:
"""Current spending information."""
amount: float
unit: str # Currency code
class ForecastSpend:
"""Forecasted spending information."""
amount: float
unit: str # Currency codeclass BudgetFilter:
"""Filtering options for budget scope."""
and_: List[BudgetFilterProperties]
or_: List[BudgetFilterProperties]
not_: BudgetFilterProperties
dimensions: BudgetComparisonExpression
tags: BudgetComparisonExpression
class BudgetFilterProperties:
"""Individual filter properties."""
dimensions: BudgetComparisonExpression
tags: BudgetComparisonExpression
class BudgetComparisonExpression:
"""Comparison expression for budget filters."""
name: str
operator: str # "In", "Contains"
values: List[str]class Notification:
"""Budget notification settings."""
enabled: bool
operator: str # "EqualTo", "GreaterThan", "GreaterThanOrEqualTo"
threshold: float # Percentage (0-1000)
contact_emails: List[str]
contact_groups: List[str]
contact_roles: List[str] # "Owner", "Contributor", "Reader"
threshold_type: str # "Actual" or "Forecasted"
locale: str # Culture code for notificationsclass BudgetsListResult:
"""Container for budget list response."""
value: List[Budget]
next_link: strclass CategoryType:
"""Budget category types."""
COST = "Cost"
USAGE = "Usage"
class TimeGrainType:
"""Time grain options for budgets."""
MONTHLY = "Monthly"
QUARTERLY = "Quarterly"
ANNUALLY = "Annually"
BILLING_MONTH = "BillingMonth"
BILLING_QUARTER = "BillingQuarter"
BILLING_ANNUAL = "BillingAnnual"
class BudgetOperatorType:
"""Budget comparison operators."""
IN = "In"
CONTAINS = "Contains"
class OperatorType:
"""Notification threshold operators."""
EQUAL_TO = "EqualTo"
GREATER_THAN = "GreaterThan"
GREATER_THAN_OR_EQUAL_TO = "GreaterThanOrEqualTo"
class ThresholdType:
"""Notification threshold types."""
ACTUAL = "Actual"
FORECASTED = "Forecasted"Install with Tessl CLI
npx tessl i tessl/pypi-azure-mgmt-consumption