Grafeas API Client Library for Python

1.22.0 · active · verified Thu Apr 16

Grafeas is an implementation of the Grafeas API, which stores and enables querying and retrieval of critical metadata about all of your software artifacts. This Python client library is part of the actively maintained `google-cloud-python` monorepo, receiving regular updates for features, bug fixes, and compatibility, ensuring robust interaction with the Grafeas service.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate the Grafeas client and list all notes within a specified Google Cloud project. Ensure your `GOOGLE_CLOUD_PROJECT` environment variable is set or replace `'your-project-id'` with your actual project ID. Authentication is handled implicitly if `GOOGLE_APPLICATION_CREDENTIALS` is set or if running in a Google Cloud environment.

import os
from grafeas import grafeas_v1

# Your Google Cloud Project ID
project_id = os.environ.get('GOOGLE_CLOUD_PROJECT', 'your-project-id')

def list_all_notes(project_id):
    """Lists all notes in a given project."""
    client = grafeas_v1.GrafeasClient()
    parent = f"projects/{project_id}"
    
    print(f"Listing notes for project: {project_id}")
    try:
        for note in client.list_notes(parent=parent):
            print(f"  Note: {note.name} (Kind: {note.kind.name})")
    except Exception as e:
        print(f"An error occurred: {e}")

if __name__ == '__main__':
    list_all_notes(project_id)

view raw JSON →