List listings (v1)

List all listings in a BigQuery Analytics Hub data exchange.

Code sample

Python

Before trying this sample, follow the Python setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Python API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

from google.api_core import exceptions
from google.cloud import bigquery_analyticshub_v1


def list_listings(project_id: str, location_id: str, data_exchange_id: str) -> None:
    """Lists listings in a BigQuery Analytics Hub data exchange.

    Args:
        project_id: The Google Cloud project ID.
        location_id: The Google Cloud region or location for the data exchange (for example, 'us').
        data_exchange_id: The ID of the data exchange.
    """
    client = bigquery_analyticshub_v1.AnalyticsHubServiceClient()

    parent = (
        f"projects/{project_id}/locations/{location_id}/dataExchanges/{data_exchange_id}"
    )

    request = bigquery_analyticshub_v1.ListListingsRequest(parent=parent)

    try:
        response = client.list_listings(request=request)
        for listing in response:
            print(f"Listing name: {listing.name}")
            print(f"Display name: {listing.display_name}")
    except exceptions.GoogleAPICallError as error:
        print(f"Request failed with API error: {error}")

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.