Registry / azure / azure-mgmt-containerinstance

azure-mgmt-containerinstance

JSON →
library10.1.0pypypi✓ verified 25d ago

The `azure-mgmt-containerinstance` library provides a client for managing Azure Container Instances, allowing programmatic creation, update, and deletion of container groups and related resources. It is part of the larger Azure SDK for Python and is currently at version 10.1.0, with frequent updates aligning with Azure service API changes and broader SDK release cycles.

pip install azure-mgmt-containerinstance azure-identity
INSTALL
IMPORT
SIG · AZURE-MGMT-CONTAIN
A
azure-mgmt-containerinstance
azurepythonv10.1.0
Install
4.0s avg
Import
589ms
Disk
43MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v10.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.622s · 44MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 4.0s · import 0.556s · 44MB
43MB installed
● package 43MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ContainerInstanceManagementClient
from azure.mgmt.containerinstance import ContainerInstanceManagementClient
DefaultAzureCredential
from azure.identity import DefaultAzureCredential
from msrestazure.azure_active_directory import ServicePrincipalCredentials
Old authentication method from v8 and earlier; modern SDK uses azure-identity.

This quickstart demonstrates how to authenticate with `DefaultAzureCredential` and create a simple Azure Container Instance (ACI) using the `ContainerInstanceManagementClient`. It sets up a container group with a single public-facing container running a hello-world image. Remember to set your Azure Subscription ID, Resource Group Name, and Location in environment variables or directly in the script.

import os from azure.identity import DefaultAzureCredential from azure.mgmt.containerinstance import ContainerInstanceManagementClient # --- Environment Variables (Replace with your actual values or ensure they are set) --- SUBSCRIPTION_ID = os.environ.get("AZURE_SUBSCRIPTION_ID", "YOUR_SUBSCRIPTION_ID") RESOURCE_GROUP_NAME = os.environ.get("AZURE_RESOURCE_GROUP", "my-aci-rg") LOCATION = os.environ.get("AZURE_LOCATION", "eastus") CONTAINER_GROUP_NAME = os.environ.get("AZURE_ACI_NAME", "my-aci-container-group") if SUBSCRIPTION_ID == "YOUR_SUBSCRIPTION_ID": raise ValueError("Please set the AZURE_SUBSCRIPTION_ID environment variable.") # Authenticate using DefaultAzureCredential (looks for env vars, managed identity, etc.) credential = DefaultAzureCredential() # Create a ContainerInstanceManagementClient client = ContainerInstanceManagementClient(credential, SUBSCRIPTION_ID) # Define the container group container_group_body = { "location": LOCATION, "containers": [ { "name": "mycontainer", "image": "mcr.microsoft.com/azuredocs/aci-helloworld", "resources": { "requests": { "cpu": 1.0, "memory_in_gb": 1.5 } }, "ports": [{"port": 80}] } ], "os_type": "Linux", "ip_address": { "type": "Public", "ports": [ { "protocol": "TCP", "port": 80 } ] } } print(f"Creating container group '{CONTAINER_GROUP_NAME}' in resource group '{RESOURCE_GROUP_NAME}'...") # Create or update the container group (this returns a poller object) lro_poller = client.container_groups.begin_create_or_update( resource_group_name=RESOURCE_GROUP_NAME, container_group_name=CONTAINER_GROUP_NAME, container_group=container_group_body ) # Wait for the operation to complete and get the result container_group = lro_poller.result() print(f"Container group '{container_group.name}' created/updated successfully.") print(f"IP Address: {container_group.ip_address.ip}") # To delete the container group (optional) # print(f"Deleting container group '{CONTAINER_GROUP_NAME}'...") # delete_poller = client.container_groups.begin_delete( # resource_group_name=RESOURCE_GROUP_NAME, # container_group_name=CONTAINER_GROUP_NAME # ) # delete_poller.result() # print(f"Container group '{CONTAINER_GROUP_NAME}' deleted.")
Debug
Known issues
breakingStarting from version 9.0.0, the `ContainerInstanceManagementClient` no longer accepts a `base_url` parameter. Authentication methods have also shifted from `msrestazure` credentials (e.g., `ServicePrincipalCredentials`) to `azure-identity` (e.g., `DefaultAzureCredential`).
fix
Use `from azure.identity import DefaultAzureCredential` for authentication and initialize the client directly with `ContainerInstanceManagementClient(credential, subscription_id)`.
affects: >=9.0.0
breakingIn version 9.0.0 and later, the `create_or_update` method for `ContainerGroups` changed parameter names. Specifically, `resource_group_name` was renamed to `resource_group_name_param` for clarity and consistency across Azure SDKs.
fix
Update calls to `client.container_groups.begin_create_or_update` to use `resource_group_name_param` instead of `resource_group_name`.
affects: >=9.0.0
gotchaMany Azure management operations, especially those that create or update resources (e.g., `begin_create_or_update`, `begin_delete`), are long-running operations (LROs). These methods return a poller object, not the final resource directly.
fix
Always call `.result()` on the poller object (e.g., `lro_poller.result()`) to wait for the operation to complete and retrieve the final resource object or status in synchronous clients. For asynchronous clients, you'd `await` the poller methods.
affects: All
gotchaResource group operations (creating container instances) require the specified resource group to already exist in Azure. If it doesn't, the operation will fail.
fix
Ensure the resource group exists before attempting to deploy container instances into it. You might need to use `azure-mgmt-resource` to create resource groups programmatically if they don't exist.
affects: All
gotchaThe `AZURE_SUBSCRIPTION_ID` environment variable is required for authenticating and managing Azure resources. Failing to set it will cause client initialization or subsequent operations to fail.
fix
Ensure the `AZURE_SUBSCRIPTION_ID` environment variable is correctly set in your environment before running the application. This is essential for the Azure SDK to identify which subscription to operate on.
affects: All
gotchaAzure SDK for Python samples and many client operations require environment variables like `AZURE_SUBSCRIPTION_ID` to be set for authentication and resource management. Failing to set these will often result in a `ValueError` or `KeyError` if the script explicitly checks for them, or authentication failures otherwise.
fix
Ensure all required environment variables, such as `AZURE_SUBSCRIPTION_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_ID`, and `AZURE_CLIENT_SECRET`, are properly configured before running the script. These are essential for authentication and identifying the target Azure subscription. You can set them using `export AZURE_SUBSCRIPTION_ID='your-subscription-id'` in your shell or similar methods depending on your environment.
affects: All
Upgrade
Version history
10.1.0latest on PyPI · released Apr 21, 2023
Audit
Dependencies
azure-identityrequiredRequired for authenticating to Azure services using modern credential types.
Agent activity
23 hits · last 30 days
node
18
OpenAI (training)
1
Resources
azure-mgmt-containerinstance — pip install azure-mgmt-containerinstance · libregistry