Azure Container Registry Client Library
The Microsoft Azure Container Registry Client Library for Python provides an interface to interact with Azure Container Registry (ACR) services. It allows developers to manage container images, repositories, and other artifacts stored in ACR. The library is currently at version 1.2.0 and follows the Azure SDK for Python's regular release cadence, ensuring updates and feature parity with the service.
Warnings
- gotcha Authentication with Azure Container Registry requires the `azure-identity` package and proper credential setup. `DefaultAzureCredential` is the recommended way, but relies on environment variables (e.g., `AZURE_CLIENT_ID`, `AZURE_CLIENT_SECRET`, `AZURE_TENANT_ID`) or other configured Azure SDK authentication methods. Without correct setup, authentication will fail.
- gotcha The authenticated identity (e.g., service principal, managed identity, user account) must have appropriate Azure RBAC roles assigned to the Container Registry. Common roles include `AcrPull` (read-only), `AcrPush` (read/write), or `Owner`/`Contributor` for full management. Insufficient permissions will result in authorization errors.
- gotcha This library (`azure-containerregistry`) is the data-plane client for interacting with repositories, images, and manifests. It should not be confused with the management-plane client (`azure-mgmt-containerregistry`), which is used for creating, updating, and deleting the Container Registry *resource itself*.
Install
-
pip install azure-containerregistry azure-identity
Imports
- ContainerRegistryClient
from azure.containerregistry import ContainerRegistryClient
- DefaultAzureCredential
from azure.identity import DefaultAzureCredential
Quickstart
import os
from azure.containerregistry import ContainerRegistryClient
from azure.identity import DefaultAzureCredential
# Set your ACR endpoint, e.g., 'https://myregistry.azurecr.io'
registry_url = os.environ.get('AZURE_CONTAINER_REGISTRY_URL', 'https://yourregistryname.azurecr.io')
# DefaultAzureCredential will try various authentication methods
# (environment variables, managed identity, VS Code, Azure CLI, etc.)
credential = DefaultAzureCredential()
client = ContainerRegistryClient(endpoint=registry_url, credential=credential)
try:
print(f"Listing repositories in {registry_url}:")
for repository_name in client.list_repository_names():
print(f"- {repository_name}")
except Exception as e:
print(f"An error occurred: {e}")
finally:
client.close()
credential.close()