Azure App Containers Management Client Library for Python
The `azure-mgmt-appcontainers` library is the Microsoft Azure Appcontainers Management Client Library for Python, enabling developers to programmatically manage Azure Container Apps resources. It provides a rich set of functionalities for interacting with Container Apps, Managed Environments, and related components. The current stable version is 4.0.0, and it is actively maintained as part of the Azure SDK for Python, with regular updates and releases.
Warnings
- breaking Version 4.0.0 introduced significant breaking changes. Several model parameters were removed (e.g., `AvailableWorkloadProfileProperties.billing_meter_category`, `ContainerApp.workload_profile_type`, `ManagedEnvironment.sku`, `VnetConfiguration.outbound_settings`, `VnetConfiguration.runtime_subnet_id`). Additionally, `WorkloadProfile` now requires a `name` parameter. Several methods in `ConnectedEnvironmentsCertificatesOperations`, `ConnectedEnvironmentsDaprComponentsOperations`, and `ConnectedEnvironmentsStoragesOperations` were deleted or renamed.
- gotcha Incorrect or missing Azure environment variables for authentication (e.g., `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`, `AZURE_SUBSCRIPTION_ID`) or for the Container App's runtime can lead to client initialization failures or application crashes. `DefaultAzureCredential` relies on these for environment-based authentication.
- gotcha Improper image references, issues with private container registry access (e.g., incorrect credentials or managed identity setup), or misconfigured container startup commands/entrypoints are common causes for Container App deployment failures and runtime errors.
- gotcha Networking and ingress misconfigurations in Azure Container Apps environments can lead to applications being inaccessible or returning unexpected HTTP errors (e.g., 403 Forbidden).
Install
-
pip install azure-mgmt-appcontainers azure-identity
Imports
- ContainerAppsAPIClient
from azure.mgmt.appcontainers import ContainerAppsAPIClient
- DefaultAzureCredential
from azure.identity import DefaultAzureCredential
Quickstart
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.appcontainers import ContainerAppsAPIClient
# Set environment variables for authentication and subscription ID
# AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET for service principal
# AZURE_SUBSCRIPTION_ID
subscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', '')
if not subscription_id:
raise ValueError("AZURE_SUBSCRIPTION_ID environment variable not set.")
# Authenticate using DefaultAzureCredential
# This credential type tries multiple authentication methods (environment variables, managed identity, etc.)
credential = DefaultAzureCredential()
# Create the Container Apps management client
client = ContainerAppsAPIClient(credential=credential, subscription_id=subscription_id)
# Example: List managed environments (replace with your desired operation)
# For a real scenario, you would specify a resource group name
print(f"Listing managed environments in subscription: {subscription_id}")
for environment in client.managed_environments.list_by_subscription():
print(f"- {environment.name} (Location: {environment.location})")