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
Retrieve all available tag keys for cost allocation and management across various Azure scopes including subscriptions, billing accounts, and management groups.
Get all available tag keys that can be used for cost allocation and resource management within a specified scope.
def get(scope: str, **kwargs) -> Optional[TagsResult]:
"""
Get all available tag keys for the defined scope.
Parameters:
- scope: The scope associated with tags operations. This includes
'/subscriptions/{subscriptionId}/' for subscription scope,
'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
'/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
'/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department scope,
'/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for EnrollmentAccount scope and
'/providers/Microsoft.Management/managementGroups/{managementGroupId}' for Management Group scope.
Returns:
Optional[TagsResult]: Available tag keys and values for the specified scope
"""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 all available tags for subscription scope
scope = f"/subscriptions/{subscription_id}"
tags_result = client.tags.get(scope=scope)
if tags_result:
print("Available tags:")
for tag in tags_result.tags:
print(f"- {tag.key}: {tag.values}")
# Get tags for a specific billing account
billing_account_scope = "/providers/Microsoft.Billing/billingAccounts/12345678-1234-1234-1234-123456789012"
billing_tags = client.tags.get(scope=billing_account_scope)
if billing_tags:
print("Billing account tags:")
for tag in billing_tags.tags:
print(f"- {tag.key}")class TagsResult:
tags: List[Tag]
class Tag:
key: str
values: List[str]Install with Tessl CLI
npx tessl i tessl/pypi-azure-mgmt-consumption