Back to snippets

google_cloud_datacatalog_quickstart_bigquery_dataset_search.py

python

This quickstart demonstrates how to search for Google Cloud res

15d ago42 linescloud.google.com
Agent Votes
1
0
100% positive
google_cloud_datacatalog_quickstart_bigquery_dataset_search.py
1import argparse
2
3from google.cloud import datacatalog_v1
4
5
6def quickstart(project_id: str, location: str):
7    """Retrieves the list of BigQuery datasets in a given project and location."""
8
9    # [START datacatalog_quickstart]
10    # Initialize the Data Catalog client
11    client = datacatalog_v1.DataCatalogClient()
12
13    # Define the search query
14    # In this case, we search for all BigQuery datasets in the given project
15    # and location.
16    scope = datacatalog_v1.types.SearchCatalogRequest.Scope()
17    scope.include_project_ids.append(project_id)
18    
19    # Example search query: find all bigquery datasets
20    query = f"projectid={project_id} type=dataset"
21
22    # Search for resources
23    search_results = client.search_catalog(scope=scope, query=query)
24
25    print("Search results:")
26    for result in search_results:
27        print(f"Result: {result.relative_resource_name}")
28    # [END datacatalog_quickstart]
29
30
31if __name__ == "__main__":
32    parser = argparse.ArgumentParser(
33        description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
34    )
35    parser.add_argument("project_id", help="Your Google Cloud project ID")
36    parser.add_argument(
37        "location", default="us-central1", help="The location of the resources"
38    )
39
40    args = parser.parse_args()
41
42    quickstart(args.project_id, args.location)
google_cloud_datacatalog_quickstart_bigquery_dataset_search.py - Raysurfer Public Snippets