Google Cloud Artifact Registry

1.21.0 · active · verified Thu Apr 09

The `google-cloud-artifact-registry` client library for Python allows developers to interact with Google Cloud Artifact Registry. This service provides a universal package manager for various artifact formats, including Docker images, Maven artifacts, npm packages, and more. The library is currently at version 1.21.0 and is part of the actively maintained Google Cloud Python client libraries, receiving frequent updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `ArtifactRegistryClient` and list repositories within a specified Google Cloud project and location. It highlights the use of `parent` resource names and iterating over paginated results.

import os
from google.cloud.artifactregistry_v1 import ArtifactRegistryClient

def list_repositories(project_id: str, location: str):
    """Lists repositories in a given project and location."""
    client = ArtifactRegistryClient()
    # The parent resource name for the project and location
    parent = f"projects/{project_id}/locations/{location}"

    try:
        print(f"Listing repositories in {parent}...")
        # list_repositories returns an iterator, common for Google Cloud APIs
        repositories = client.list_repositories(parent=parent)
        found = False
        for repo in repositories:
            print(f"- {repo.name} (Format: {repo.format.name}, Description: {repo.description})")
            found = True
        if not found:
            print("No repositories found.")
    except Exception as e:
        print(f"Error listing repositories: {e}")

if __name__ == "__main__":
    # Set these environment variables or replace the placeholders
    PROJECT_ID = os.environ.get("GCP_PROJECT_ID", "your-gcp-project-id")
    LOCATION = os.environ.get("GCP_LOCATION", "us-central1") # e.g., 'us-central1', 'europe-west1'

    if PROJECT_ID == "your-gcp-project-id":
        print("Please set the GCP_PROJECT_ID environment variable or replace 'your-gcp-project-id'.")
        print("Also ensure you are authenticated (e.g., `gcloud auth application-default login`).")
    else:
        list_repositories(PROJECT_ID, LOCATION)

view raw JSON →