{"id":7275,"library":"grafeas","title":"Grafeas API Client Library for Python","description":"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.","status":"active","version":"1.22.0","language":"en","source_language":"en","source_url":"https://github.com/googleapis/google-cloud-python/tree/main/packages/grafeas","tags":["google-cloud","grafeas","security","supply-chain-security","vulnerability-management","artifact-metadata","container-security"],"install":[{"cmd":"pip install grafeas","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required Python version.","package":"python","optional":false},{"reason":"Core library for Google API clients, handling underlying RPC communication and common features.","package":"google-api-core","optional":false},{"reason":"Handles authentication with Google Cloud services.","package":"google-auth","optional":false}],"imports":[{"note":"The primary synchronous client for interacting with the Grafeas API.","symbol":"GrafeasClient","correct":"from grafeas import grafeas_v1\nclient = grafeas_v1.GrafeasClient()"},{"note":"The asynchronous client for non-blocking operations.","symbol":"GrafeasAsyncClient","correct":"from grafeas import grafeas_v1\nclient = grafeas_v1.GrafeasAsyncClient()"}],"quickstart":{"code":"import os\nfrom grafeas import grafeas_v1\n\n# Your Google Cloud Project ID\nproject_id = os.environ.get('GOOGLE_CLOUD_PROJECT', 'your-project-id')\n\ndef list_all_notes(project_id):\n    \"\"\"Lists all notes in a given project.\"\"\"\n    client = grafeas_v1.GrafeasClient()\n    parent = f\"projects/{project_id}\"\n    \n    print(f\"Listing notes for project: {project_id}\")\n    try:\n        for note in client.list_notes(parent=parent):\n            print(f\"  Note: {note.name} (Kind: {note.kind.name})\")\n    except Exception as e:\n        print(f\"An error occurred: {e}\")\n\nif __name__ == '__main__':\n    list_all_notes(project_id)","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade to `grafeas>=1.0.0` and update import paths and client instantiation as per the latest documentation, typically using `from grafeas import grafeas_v1`.","message":"The `grafeas` library underwent significant breaking changes in version 1.0.0 due to a complete regeneration using Google's microgenerator. This resulted in a change to the client surface and package structure compared to older versions (e.g., `grafeas<1.0.0`).","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Upgrade your Python environment to version 3.9 or higher. For Python 2.7, the last compatible version was `grafeas==0.4.1`.","message":"Support for older Python versions (Python <= 3.8) has been dropped. If you are using an unsupported Python version, you may encounter installation or runtime errors.","severity":"breaking","affected_versions":"<=3.8"},{"fix":"Ensure that `GOOGLE_APPLICATION_CREDENTIALS` environment variable points to a valid service account key file, or that your execution environment (e.g., GCE, Cloud Run, Cloud Functions) has appropriate service account permissions. Alternatively, provide credentials explicitly during client instantiation.","message":"Incorrect or missing authentication setup is a common issue when using Google Cloud client libraries. Without proper authentication, API calls will result in `Unauthorized` errors.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Run `pip install grafeas` to install the library. Double-check the spelling of 'grafeas' in your `import` statements. If using a virtual environment, ensure it is activated.","cause":"The `grafeas` package is not installed in your current Python environment, or there's a typo in the import statement, or your Python environment's path is incorrectly configured.","error":"ModuleNotFoundError: No module named 'grafeas'"},{"fix":"Grant the appropriate IAM role (e.g., `roles/containeranalysis.viewer` for read-only, `roles/containeranalysis.editor` for read/write) to the service account or user interacting with Grafeas on the Google Cloud project.","cause":"The authenticated identity (service account or user) does not have the necessary IAM permissions to access Grafeas resources in the specified project. This often happens if the 'Grafeas Viewer' or 'Grafeas Editor' role is missing.","error":"google.api_core.exceptions.PermissionDenied: 403 Permission denied on resource project projects/your-project-id"},{"fix":"Update your import statement to `from grafeas import grafeas_v1` and then instantiate the client using `client = grafeas_v1.GrafeasClient()`. For asynchronous operations, use `grafeas_v1.GrafeasAsyncClient()`.","cause":"This usually indicates that you are trying to import `GrafeasClient` directly from the top-level `grafeas` package, or you are using an outdated import pattern from a pre-1.0.0 version of the library.","error":"AttributeError: module 'grafeas' has no attribute 'GrafeasClient'"}]}