Microsoft Azure Image Builder Client Library for Python
This is the Microsoft Azure Image Builder Client Library for Python. It provides the necessary tools to interact with the Azure VM Image Builder service to define, build, and distribute custom virtual machine images. The current version is 1.4.0, and it follows the Azure SDK release cadence, with frequent updates for features and bug fixes.
Warnings
- breaking The credential system was revamped in the 1.x.x series (e.g., 1.0.0b1). `azure.common.credentials` and `msrestazure.azure_active_directory` are no longer supported. Use classes from `azure-identity` (e.g., `DefaultAzureCredential`).
- breaking API version 2021-10-01 introduced a change to the error schema for Image Builder. Automations parsing error outputs from earlier API versions may break.
- breaking After March 31, 2026, new virtual networks in Azure will default to private subnets. This affects AIB templates that specify `subnetId` or `containerInstanceSubnetId`, requiring explicit outbound access for build/validation VMs if needed.
- gotcha Azure VM Image Builder requires a user-assigned managed identity with specific permissions (e.g., 'Managed Identity Operator' role, read/write to images, read from storage for scripts) to function correctly. Lack of permissions is a common cause of failures.
- deprecated Support for Python 2.7 by Azure SDK Python packages officially ended on January 1, 2022.
- gotcha The 'file' customizer in Azure Image Builder is only suitable for small file downloads (< 20MB). For larger files, it's recommended to use a script or inline command to download them (e.g., `wget`, `curl`, `Invoke-WebRequest`).
Install
-
pip install azure-mgmt-imagebuilder azure-identity
Imports
- ImageBuilderClient
from azure.mgmt.imagebuilder import ImageBuilderClient
- DefaultAzureCredential
from azure.identity import DefaultAzureCredential
Quickstart
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.imagebuilder import ImageBuilderClient
# Set environment variables for authentication and subscription
# AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
# AZURE_SUBSCRIPTION_ID
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "YOUR_SUBSCRIPTION_ID")
resource_group_name = "myResourceGroup"
# Authenticate and create client
try:
credential = DefaultAzureCredential()
client = ImageBuilderClient(credential=credential, subscription_id=subscription_id)
print(f"ImageBuilderClient created for subscription: {subscription_id}")
# Example: List all image templates in a resource group
print(f"\nListing image templates in resource group '{resource_group_name}':")
templates = client.virtual_machine_image_templates.list_by_resource_group(resource_group_name=resource_group_name)
for template in templates:
print(f" - {template.name} ({template.id})")
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure environment variables (AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET, AZURE_SUBSCRIPTION_ID) are set correctly and the resource group exists.")