Microsoft Azure Billing Client Library for Python

7.0.0 · active · verified Thu Apr 09

The azure-mgmt-billing library is the Microsoft Azure Billing Client Library for Python. It provides an interface for managing Azure billing resources. As part of the wider Azure SDK for Python, it adheres to modern SDK guidelines and receives regular updates to support new Azure features and improvements. The current stable version is 7.0.0.

Warnings

Install

Imports

Quickstart

Initializes the BillingManagementClient using DefaultAzureCredential for authentication. This requires Azure Active Directory environment variables (AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET) and AZURE_SUBSCRIPTION_ID to be set. It then demonstrates how to create a client instance.

import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.billing import BillingManagementClient

# Set these environment variables for authentication
# AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
# AZURE_SUBSCRIPTION_ID (for billing operations)

subscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', 'YOUR_SUBSCRIPTION_ID')

# Authenticate using DefaultAzureCredential
credential = DefaultAzureCredential()

# Create a BillingManagementClient
billing_client = BillingManagementClient(credential=credential, subscription_id=subscription_id)

# Example: List billing accounts (this operation might not require subscription_id directly, 
# but the client is often initialized with it for consistency across management clients)
# Replace with an actual operation relevant to your billing scenario
# For example: print(list(billing_client.billing_accounts.list()))
print('BillingManagementClient initialized successfully.')

view raw JSON →