Add this skill
npx mdskills install sickn33/azure-containerregistry-pyComprehensive SDK reference with authentication, CRUD operations, and cleanup patterns.
1---2name: azure-containerregistry-py3description: |4 Azure Container Registry SDK for Python. Use for managing container images, artifacts, and repositories.5 Triggers: "azure-containerregistry", "ContainerRegistryClient", "container images", "docker registry", "ACR".6package: azure-containerregistry7---89# Azure Container Registry SDK for Python1011Manage container images, artifacts, and repositories in Azure Container Registry.1213## Installation1415```bash16pip install azure-containerregistry17```1819## Environment Variables2021```bash22AZURE_CONTAINERREGISTRY_ENDPOINT=https://<registry-name>.azurecr.io23```2425## Authentication2627### Entra ID (Recommended)2829```python30from azure.containerregistry import ContainerRegistryClient31from azure.identity import DefaultAzureCredential3233client = ContainerRegistryClient(34 endpoint=os.environ["AZURE_CONTAINERREGISTRY_ENDPOINT"],35 credential=DefaultAzureCredential()36)37```3839### Anonymous Access (Public Registry)4041```python42from azure.containerregistry import ContainerRegistryClient4344client = ContainerRegistryClient(45 endpoint="https://mcr.microsoft.com",46 credential=None,47 audience="https://mcr.microsoft.com"48)49```5051## List Repositories5253```python54client = ContainerRegistryClient(endpoint, DefaultAzureCredential())5556for repository in client.list_repository_names():57 print(repository)58```5960## Repository Operations6162### Get Repository Properties6364```python65properties = client.get_repository_properties("my-image")66print(f"Created: {properties.created_on}")67print(f"Modified: {properties.last_updated_on}")68print(f"Manifests: {properties.manifest_count}")69print(f"Tags: {properties.tag_count}")70```7172### Update Repository Properties7374```python75from azure.containerregistry import RepositoryProperties7677client.update_repository_properties(78 "my-image",79 properties=RepositoryProperties(80 can_delete=False,81 can_write=False82 )83)84```8586### Delete Repository8788```python89client.delete_repository("my-image")90```9192## List Tags9394```python95for tag in client.list_tag_properties("my-image"):96 print(f"{tag.name}: {tag.created_on}")97```9899### Filter by Order100101```python102from azure.containerregistry import ArtifactTagOrder103104# Most recent first105for tag in client.list_tag_properties(106 "my-image",107 order_by=ArtifactTagOrder.LAST_UPDATED_ON_DESCENDING108):109 print(f"{tag.name}: {tag.last_updated_on}")110```111112## Manifest Operations113114### List Manifests115116```python117from azure.containerregistry import ArtifactManifestOrder118119for manifest in client.list_manifest_properties(120 "my-image",121 order_by=ArtifactManifestOrder.LAST_UPDATED_ON_DESCENDING122):123 print(f"Digest: {manifest.digest}")124 print(f"Tags: {manifest.tags}")125 print(f"Size: {manifest.size_in_bytes}")126```127128### Get Manifest Properties129130```python131manifest = client.get_manifest_properties("my-image", "latest")132print(f"Digest: {manifest.digest}")133print(f"Architecture: {manifest.architecture}")134print(f"OS: {manifest.operating_system}")135```136137### Update Manifest Properties138139```python140from azure.containerregistry import ArtifactManifestProperties141142client.update_manifest_properties(143 "my-image",144 "latest",145 properties=ArtifactManifestProperties(146 can_delete=False,147 can_write=False148 )149)150```151152### Delete Manifest153154```python155# Delete by digest156client.delete_manifest("my-image", "sha256:abc123...")157158# Delete by tag159manifest = client.get_manifest_properties("my-image", "old-tag")160client.delete_manifest("my-image", manifest.digest)161```162163## Tag Operations164165### Get Tag Properties166167```python168tag = client.get_tag_properties("my-image", "latest")169print(f"Digest: {tag.digest}")170print(f"Created: {tag.created_on}")171```172173### Delete Tag174175```python176client.delete_tag("my-image", "old-tag")177```178179## Upload and Download Artifacts180181```python182from azure.containerregistry import ContainerRegistryClient183184client = ContainerRegistryClient(endpoint, DefaultAzureCredential())185186# Download manifest187manifest = client.download_manifest("my-image", "latest")188print(f"Media type: {manifest.media_type}")189print(f"Digest: {manifest.digest}")190191# Download blob192blob = client.download_blob("my-image", "sha256:abc123...")193with open("layer.tar.gz", "wb") as f:194 for chunk in blob:195 f.write(chunk)196```197198## Async Client199200```python201from azure.containerregistry.aio import ContainerRegistryClient202from azure.identity.aio import DefaultAzureCredential203204async def list_repos():205 credential = DefaultAzureCredential()206 client = ContainerRegistryClient(endpoint, credential)207208 async for repo in client.list_repository_names():209 print(repo)210211 await client.close()212 await credential.close()213```214215## Clean Up Old Images216217```python218from datetime import datetime, timedelta, timezone219220cutoff = datetime.now(timezone.utc) - timedelta(days=30)221222for manifest in client.list_manifest_properties("my-image"):223 if manifest.last_updated_on < cutoff and not manifest.tags:224 print(f"Deleting {manifest.digest}")225 client.delete_manifest("my-image", manifest.digest)226```227228## Client Operations229230| Operation | Description |231|-----------|-------------|232| `list_repository_names` | List all repositories |233| `get_repository_properties` | Get repository metadata |234| `delete_repository` | Delete repository and all images |235| `list_tag_properties` | List tags in repository |236| `get_tag_properties` | Get tag metadata |237| `delete_tag` | Delete specific tag |238| `list_manifest_properties` | List manifests in repository |239| `get_manifest_properties` | Get manifest metadata |240| `delete_manifest` | Delete manifest by digest |241| `download_manifest` | Download manifest content |242| `download_blob` | Download layer blob |243244## Best Practices2452461. **Use Entra ID** for authentication in production2472. **Delete by digest** not tag to avoid orphaned images2483. **Lock production images** with can_delete=False2494. **Clean up untagged manifests** regularly2505. **Use async client** for high-throughput operations2516. **Order by last_updated** to find recent/old images2527. **Check manifest.tags** before deleting to avoid removing tagged images253
Full transparency — inspect the skill content before installing.