{"id":9784,"library":"google-cloud-recommender","title":"Google Cloud Recommender","description":"The `google-cloud-recommender` client library provides a Python interface for the Google Cloud Recommender API. This service delivers proactive recommendations and insights to help users optimize costs, improve performance, enhance security, and achieve operational excellence across their Google Cloud resources. The library is currently at version 2.21.0 and follows Google's frequent release cadence, often receiving updates multiple times a month as part of the broader `google-cloud-python` monorepo.","status":"active","version":"2.21.0","language":"python","source_language":"en","source_url":"https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-recommender","tags":["google-cloud","gcp","recommender","api-client","optimization","cloud-management"],"install":[{"cmd":"pip install google-cloud-recommender","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"wrong":"from google.cloud import recommender_v1","symbol":"RecommenderClient","correct":"from google.cloud import recommender_v1"}],"quickstart":{"code":"import os\nfrom google.cloud import recommender_v1\n\n# Set your Google Cloud Project ID and a specific location\nproject_id = os.environ.get('GCP_PROJECT_ID', 'your-project-id')\nlocation = 'global' # Recommender often uses 'global' or a specific region\n\n# Initialize the client\nclient = recommender_v1.RecommenderClient()\n\n# Define the recommender name (e.g., for IAM policy recommendations)\n# Common recommenders: google.iam.policy.Recommender, google.compute.instance.MachineTypeRecommender\nrecommender_name = f\"projects/{project_id}/locations/{location}/recommenders/google.iam.policy.Recommender\"\n\n# List recommendations for a given recommender\ntry:\n    # Iterate through the paginated results\n    for recommendation in client.list_recommendations(parent=recommender_name):\n        print(f\"Recommendation ID: {recommendation.name.split('/')[-1]}\")\n        print(f\"Description: {recommendation.description}\")\n        print(f\"State: {recommendation.state_info.state.name}\")\n        if recommendation.primary_impact:\n            print(f\"Primary Impact: {recommendation.primary_impact.category.name}\")\n        print('---\\n')\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Ensure you have `recommender.recommendations.list` permission and `GCP_PROJECT_ID` is set correctly.\")\n","lang":"python","description":"This quickstart demonstrates how to initialize the `RecommenderClient` and list recommendations for a specific recommender (e.g., IAM policy recommendations) within a Google Cloud project. It uses environment variables for project ID, which is a best practice for authentication. Remember to enable the Recommender API and set up appropriate IAM permissions (e.g., `recommender.recommendations.list`)."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or higher (e.g., `python3.9 -m pip install google-cloud-recommender`).","message":"Older Python versions (e.g., 3.8 and below) are no longer supported. The library now requires Python 3.9 or newer. Ensure your development and deployment environments meet this requirement to avoid installation failures or runtime errors.","severity":"breaking","affected_versions":"<=2.0.0 (older versions), >=2.1.0 (requires >=3.9)"},{"fix":"Always construct resource names carefully following the documentation's prescribed format, using f-strings or `RecommenderClient.common_location_path` helpers.","message":"Resource names for Google Cloud Recommender API calls (e.g., `parent`, `name`) must follow a strict, fully-qualified format (e.g., `projects/project-id/locations/location/recommenders/recommender-id`). Incorrect formatting will lead to `InvalidArgument` errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure the service account or user invoking the API has the necessary `roles/recommender.viewer` or custom roles with appropriate permissions granted at the project or resource level.","message":"The Recommender API requires specific IAM permissions to list or get recommendations (e.g., `recommender.recommendations.list` for the target resource type). Lacking these permissions will result in a 403 Permission Denied error.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use `RecommenderClient` for blocking calls and `RecommenderAsyncClient` with `await` in an `async` context for non-blocking I/O. Do not interchange them without proper understanding.","message":"The `google-cloud-recommender` library provides both synchronous (`RecommenderClient`) and asynchronous (`RecommenderAsyncClient`) clients. Mixing methods or attempting to `await` on synchronous client calls will result in `TypeError` or unexpected behavior.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'2.21.0':52 'achiev':38 'across':41 'api':20,83 'api-cli':82 'broader':71 'cadenc':59 'client':9,84 'cloud':2,7,18,44,74,79,87 'cloud-manag':86 'cost':32 'current':49 'deliv':23 'enhanc':35 'excel':40 'follow':54 'frequent':57 'gcp':80 'googl':1,6,17,43,55,73,78 'google-cloud':77 'google-cloud-python':72 'google-cloud-recommend':5 'help':29 'improv':33 'insight':27 'interfac':14 'librari':10,47 'manag':88 'monorepo':76 'month':66 'multipl':63 'often':60 'oper':39 'optim':31,85 'part':68 'perform':34 'proactiv':24 'provid':11 'python':13,75 'receiv':61 'recommend':3,8,19,25,81 'releas':58 'resourc':45 'secur':36 'servic':22 'time':64 'updat':62 'user':30 'version':51","created_at":"2026-04-17T01:20:42.274748+00:00","updated_at":"2026-04-17T01:20:42.274748+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"2.21.0","cli_name":"","cli_version":null,"type":"library","homepage":"https://cloud.google.com/recommender","github":"https://github.com/googleapis/google-cloud-python","docs":null,"changelog":null,"pypi":"https://pypi.org/project/google-cloud-recommender/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["gcp","ai-ml","observability"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-30","last_verified":"2026-06-30","next_check":"2026-07-30","install_tag":null}}