Google Cloud Quotas API Client Library

0.6.0 · active · verified Fri Apr 17

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import os
from google.cloud.quotas_v1 import QuotasClient

# Ensure GOOGLE_CLOUD_PROJECT environment variable is set or replace with your actual project ID.
# Ensure GOOGLE_APPLICATION_CREDENTIALS points to a service account key file
# or that you have logged in via `gcloud auth application-default login`.
project_id = os.environ.get("GOOGLE_CLOUD_PROJECT", "your-project-id")
location = "global" # Quotas are often global or regional for many services

client = QuotasClient()
parent_resource = f"projects/{project_id}/locations/{location}"

try:
    print(f"Attempting to list quotas for parent: {parent_resource}")
    # Iterate through the first few quotas, as there can be many.
    for i, quota in enumerate(client.list_quotas(parent=parent_resource)):
        print(f"  Quota: {quota.name}, Metric: {quota.quota_metric}, Value: {quota.value}, Limit: {quota.limit}")
        if i >= 2: # Print up to 3 quotas
            break
except Exception as e:
    print(f"An error occurred: {e}")
    print("Possible causes: Missing permissions (e.g., serviceusage.quotas.get), incorrect project ID, or authentication issues.")
    print("Verify GOOGLE_CLOUD_PROJECT is set correctly and your credentials have the required roles.")

view raw JSON →