Azure Container Service Management Client Library
The `azure-mgmt-containerservice` library is the Microsoft Azure Container Service Management Client Library for Python, enabling programmatic interaction with Azure Kubernetes Service (AKS) and other container-related resources. It is currently at version 41.0.0 and frequently updated to support the latest Azure Container Service APIs, with a release cadence that includes multiple major and minor versions throughout the year. [2, 13]
Warnings
- breaking Version 41.0.0 and newer packages now exclusively target the latest API-Version available on Azure, removing APIs from older versions. Applications relying on specific, non-latest API versions must pin the package to a previous release. [2, 3]
- breaking The client operation group `ContainerServiceClient.container_service` has been deleted or renamed in version 41.0.0. [2]
- deprecated Older Azure SDK authentication methods, such as those using `azure.common.credentials`, are deprecated. The `azure-identity` library should be used for modern token-based authentication. [1, 6, 18]
- gotcha Python 2.7 support for Azure SDK Python packages ended on January 1, 2022. This package requires Python 3.9+. [2, 13]
Install
-
pip install azure-mgmt-containerservice azure-identity
Imports
- ContainerServiceClient
from azure.mgmt.containerservice import ContainerServiceClient
- DefaultAzureCredential
from azure.identity import DefaultAzureCredential
Quickstart
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.containerservice import ContainerServiceClient
# Set environment variables for authentication:
# AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
# And AZURE_SUBSCRIPTION_ID
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "")
# Authenticate with Azure
credential = DefaultAzureCredential()
# Create a Container Service client
client = ContainerServiceClient(credential=credential, subscription_id=subscription_id)
print(f"Successfully created Azure Container Service client for subscription: {subscription_id}")
# Example: List managed clusters (actual operation not shown for brevity)
# for cluster in client.managed_clusters.list():
# print(f"Cluster Name: {cluster.name}, Location: {cluster.location}")