{"id":4554,"library":"google-cloud-asset","title":"Google Cloud Asset","description":"The `google-cloud-asset` client library for Python provides programmatic access to the Google Cloud Asset Inventory API. It allows users to track, analyze, and export metadata for Google Cloud resources and IAM policies, maintaining a five-week history of changes. Part of the `google-cloud-python` monorepo, it receives regular updates. The current version is 4.3.0.","status":"active","version":"4.3.0","language":"en","source_language":"en","source_url":"https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-asset","tags":["google cloud","asset inventory","cloud security","governance","compliance"],"install":[{"cmd":"pip install google-cloud-asset","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Required runtime environment. Version 4.x requires Python 3.9 or newer.","package":"Python","optional":false},{"reason":"Core library for Google API clients, handles requests, retries, and pagination.","package":"google-api-core","optional":false},{"reason":"Handles authentication for Google Cloud services, including Application Default Credentials.","package":"google-auth","optional":false},{"reason":"Used for serialization and deserialization of API messages.","package":"protobuf","optional":false}],"imports":[{"note":"The API version is typically part of the import path for Google Cloud client libraries.","symbol":"AssetServiceClient","correct":"from google.cloud import asset_v1\nclient = asset_v1.AssetServiceClient()"},{"note":"Data models are usually nested under the versioned client module.","symbol":"Asset","correct":"from google.cloud import asset_v1\nasset = asset_v1.Asset()"}],"quickstart":{"code":"import os\nfrom google.cloud import asset_v1\n\ndef list_all_assets(project_id: str):\n    \"\"\"Lists all assets in a given project.\"\"\"\n    if not project_id:\n        raise ValueError(\"GOOGLE_CLOUD_PROJECT environment variable not set. Please set it or provide a project ID directly.\")\n\n    client = asset_v1.AssetServiceClient()\n    # The scope can be a project, folder, or organization\n    # Example: 'projects/YOUR_PROJECT_ID', 'folders/YOUR_FOLDER_ID', 'organizations/YOUR_ORG_ID'\n    parent_scope = f\"projects/{project_id}\"\n\n    # Call the API to search all resources. Returns all asset types by default if none are specified.\n    request = asset_v1.SearchAllResourcesRequest(scope=parent_scope)\n    \n    print(f\"Listing assets for scope: {parent_scope}\")\n    try:\n        for asset in client.search_all_resources(request=request):\n            print(f\"Asset Name: {asset.name}, Type: {asset.asset_type}, State: {asset.state}\")\n    except Exception as e:\n        print(f\"Error listing assets: {e}\")\n\nif __name__ == \"__main__\":\n    # Set this environment variable or replace directly with your GCP Project ID\n    project_id = os.environ.get(\"GOOGLE_CLOUD_PROJECT\", \"\") \n    \n    # For local development, ensure Application Default Credentials (ADC) are set up:\n    # Run `gcloud auth application-default login` in your terminal.\n    # Or, set the GOOGLE_APPLICATION_CREDENTIALS environment variable \n    # to the path of a service account key file.\n    \n    list_all_assets(project_id)","lang":"python","description":"This quickstart demonstrates how to initialize the `AssetServiceClient` and use it to list all resources within a specified Google Cloud project. It relies on Application Default Credentials for authentication."},"warnings":[{"fix":"Upgrade your Python environment to 3.9+ or pin the library version to `google-cloud-asset<4`.","message":"Version 4.x of `google-cloud-asset` requires Python 3.9 or newer. Projects using older Python versions (3.8 or below) must upgrade their Python environment or use an older major version of the library.","severity":"breaking","affected_versions":"4.x.x and higher"},{"fix":"Ensure ADC is correctly configured for your environment. For local development, run `gcloud auth application-default login`. For production, use a service account with appropriate permissions.","message":"Authentication is primarily handled via Application Default Credentials (ADC). Misconfiguration of ADC, such as not running `gcloud auth application-default login` for local development or not attaching a service account to a production workload, will result in authentication errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Configure Python's standard logging module to handle logs from `google.cloud.asset` explicitly, paying attention to log destination and access controls.","message":"The library's logging can contain sensitive information. By default, logging events are not handled. If enabled, ensure that log storage and access are properly secured to prevent exposure of sensitive metadata.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always construct resource names using the prescribed format for the specific API method, typically found in the client library documentation or API reference.","message":"Many API calls require a correctly formatted 'scope' (e.g., `projects/PROJECT_ID`, `folders/FOLDER_ID`, or `organizations/ORG_ID`). Incorrectly formatted resource names or scopes are a common source of API errors.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}