Microsoft Azure Billing Client Library for Python
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
- breaking Version 7.0.0 introduced significant breaking changes, including the deletion or renaming of client operation groups such as 'BillingManagementClient.instructions', 'BillingManagementClient.billing_role_definitions', and 'BillingManagementClient.billing_periods'. Additionally, the 'Agreement' model had its 'agreement_link', 'category', 'acceptance_mode', and 'effective_date' instance variables deleted or renamed.
- breaking The Azure SDK for Python underwent a major regeneration around version 6.0.0. This change revamped the credential system (deprecating `azure.common.credentials` and `msrestazure.azure_active_directory` in favor of `azure-identity`), renamed the `credentials` parameter to `credential`, removed the `config` attribute from clients, and introduced the `begin_` prefix for long-running asynchronous operations (LROs).
- deprecated Support for Python 2.7 in Azure SDK Python packages officially ended on January 1, 2022. Using this library with Python 2.7 is unsupported and may lead to security vulnerabilities or unexpected behavior.
- gotcha Many resource management operations in the Azure SDK for Python (especially those involving creating, updating, or deleting resources) are asynchronous and return an `LROPoller` object. These methods are typically prefixed with `begin_`.
Install
-
pip install azure-mgmt-billing azure-identity
Imports
- BillingManagementClient
from azure.mgmt.billing import BillingManagementClient
- DefaultAzureCredential
from azure.identity import DefaultAzureCredential
Quickstart
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.')