{"id":9783,"library":"google-cloud-quotas","title":"Google Cloud Quotas API Client Library","description":"The `google-cloud-quotas` library is the official Python client for the Google Cloud Quotas API. It allows developers to programmatically list and manage service quotas for their Google Cloud projects. As part of the larger `google-cloud-python` monorepo, it receives updates as new API features are released, typically aligning with the Google Cloud release cycle.","status":"active","version":"0.6.0","language":"en","source_language":"en","source_url":"https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-quotas","tags":["google cloud","quotas","api client","gcp"],"install":[{"cmd":"pip install google-cloud-quotas","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core library for interacting with Google APIs, handles API requests, responses, and errors.","package":"google-api-core","optional":false},{"reason":"Manages authentication with Google Cloud services.","package":"google-auth","optional":false},{"reason":"Provides Pythonic wrappers for Protobuf messages used by Google APIs.","package":"proto-plus","optional":false},{"reason":"Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data.","package":"protobuf","optional":false}],"imports":[{"note":"The API client is versioned under `quotas_v1`, not directly under `quotas`.","wrong":"from google.cloud.quotas import QuotasClient","symbol":"QuotasClient","correct":"from google.cloud.quotas_v1 import QuotasClient"}],"quickstart":{"code":"import os\nfrom google.cloud.quotas_v1 import QuotasClient\n\n# Ensure GOOGLE_CLOUD_PROJECT environment variable is set or replace with your actual project ID.\n# Ensure GOOGLE_APPLICATION_CREDENTIALS points to a service account key file\n# or that you have logged in via `gcloud auth application-default login`.\nproject_id = os.environ.get(\"GOOGLE_CLOUD_PROJECT\", \"your-project-id\")\nlocation = \"global\" # Quotas are often global or regional for many services\n\nclient = QuotasClient()\nparent_resource = f\"projects/{project_id}/locations/{location}\"\n\ntry:\n    print(f\"Attempting to list quotas for parent: {parent_resource}\")\n    # Iterate through the first few quotas, as there can be many.\n    for i, quota in enumerate(client.list_quotas(parent=parent_resource)):\n        print(f\"  Quota: {quota.name}, Metric: {quota.quota_metric}, Value: {quota.value}, Limit: {quota.limit}\")\n        if i >= 2: # Print up to 3 quotas\n            break\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Possible causes: Missing permissions (e.g., serviceusage.quotas.get), incorrect project ID, or authentication issues.\")\n    print(\"Verify GOOGLE_CLOUD_PROJECT is set correctly and your credentials have the required roles.\")\n","lang":"python","description":"This quickstart demonstrates how to initialize the `QuotasClient` and list the quotas for a specified Google Cloud project and location. It assumes default authentication is set up (e.g., `GOOGLE_APPLICATION_CREDENTIALS` or `gcloud auth application-default login`). Remember to replace 'your-project-id' or set the `GOOGLE_CLOUD_PROJECT` environment variable."},"warnings":[{"fix":"Upgrade your Python environment to 3.9+ using tools like `pyenv` or `conda`.","message":"The `google-cloud-quotas` library requires Python 3.9 or newer. Running on older Python versions will lead to installation or runtime errors.","severity":"gotcha","affected_versions":"<=0.6.0"},{"fix":"Ensure `GOOGLE_APPLICATION_CREDENTIALS` environment variable points to a valid service account key file, or run `gcloud auth application-default login` to set up user credentials. The service account/user must have the necessary IAM roles (e.g., `Service Usage Viewer`).","message":"Authentication with Google Cloud APIs is a common hurdle. If you encounter `DefaultCredentialsError` or similar authentication failures, your environment credentials are not properly configured.","severity":"gotcha","affected_versions":"All"},{"fix":"Construct the `parent` string carefully, for example: `f\"projects/{project_id}/locations/global\"` or `f\"projects/{project_id}/locations/us-central1\"`.","message":"The `parent` argument for `list_quotas` must follow a specific format: `projects/{project_id}/locations/{location_id}`. Incorrect formatting will result in an `InvalidArgument` error.","severity":"gotcha","affected_versions":"All"},{"fix":"Grant the service account or user making the API call the `roles/serviceusage.serviceUsageViewer` role or a custom role with `serviceusage.quotas.get` permission on the target project.","message":"Even with correct authentication, API calls might fail due to insufficient IAM permissions. Listing quotas requires roles like 'Service Usage Viewer' (`serviceusage.quotas.get`).","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run `pip install google-cloud-quotas` to install the library.","cause":"The `google-cloud-quotas` library is not installed or not available in the current Python environment.","error":"ModuleNotFoundError: No module named 'google.cloud.quotas_v1'"},{"fix":"Set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to the path of your service account key file, or run `gcloud auth application-default login` for user credentials.","cause":"The client library cannot find valid Google Cloud authentication credentials in the environment.","error":"google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or provide a project in google-cloud-core explicitly."},{"fix":"Ensure the `parent` argument is in the format `projects/{project_id}/locations/{location_id}` (e.g., `projects/my-project/locations/global`). Double-check all other parameters for correctness.","cause":"Often caused by an incorrectly formatted `parent` resource name or other request parameters.","error":"google.api_core.exceptions.InvalidArgument: 400 Request contains an invalid argument."}]}