Azure Container Registry Client Library

1.2.0 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with Azure Container Registry using `DefaultAzureCredential` and then list all repository names within the specified registry. Ensure the `AZURE_CONTAINER_REGISTRY_URL` environment variable is set to your registry's URL (e.g., `https://myregistry.azurecr.io`) and that your authenticated identity has sufficient permissions (e.g., 'AcrPull' role).

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()

view raw JSON →