Get an image

This sample retrieves detailed information about a single image from a project.

Code sample


Before trying this sample, follow the Python setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Python API reference documentation.

To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

from import compute_v1

def get_image(project_id: str, image_name: str) -> compute_v1.Image:
    Retrieve detailed information about a single image from a project.

        project_id: project ID or project number of the Cloud project you want to list images from.
        image_name: name of the image you want to get details of.

        An instance of compute_v1.Image object with information about specified image.
    image_client = compute_v1.ImagesClient()
    return image_client.get(project=project_id, image=image_name)

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.