List datasets Stay organized with collections Save and categorize content based on your preferences.
Lists all existing datasets in a project.
Explore further
For detailed documentation that includes this code sample, see the following:
Code sample
C#
Before trying this sample, follow theC# setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryC# API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
usingGoogle.Cloud.BigQuery.V2;usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;publicclassBigQueryListDatasets{publicvoidListDatasets(stringprojectId="your-project-id"){BigQueryClientclient=BigQueryClient.Create(projectId);// Retrieve list of datasets in projectList<BigQueryDataset>datasets=client.ListDatasets().ToList();// Display the resultsif(datasets.Count >0){Console.WriteLine($"Datasets in project {projectId}:");foreach(vardatasetindatasets){Console.WriteLine($"\t{dataset.Reference.DatasetId}");}}else{Console.WriteLine($"{projectId} does not contain any datasets.");}}}Go
Before trying this sample, follow theGo setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryGo API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
import("context""fmt""io""cloud.google.com/go/bigquery""google.golang.org/api/iterator")// listDatasets demonstrates iterating through the collection of datasets in a project.funclistDatasets(projectIDstring,wio.Writer)error{// projectID := "my-project-id"ctx:=context.Background()client,err:=bigquery.NewClient(ctx,projectID)iferr!=nil{returnfmt.Errorf("bigquery.NewClient: %w",err)}deferclient.Close()it:=client.Datasets(ctx)for{dataset,err:=it.Next()iferr==iterator.Done{break}iferr!=nil{returnerr}fmt.Fprintln(w,dataset.DatasetID)}returnnil}Java
Before trying this sample, follow theJava setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryJava API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
importcom.google.api.gax.paging.Page;importcom.google.cloud.bigquery.BigQuery;importcom.google.cloud.bigquery.BigQuery.DatasetListOption;importcom.google.cloud.bigquery.BigQueryException;importcom.google.cloud.bigquery.BigQueryOptions;importcom.google.cloud.bigquery.Dataset;publicclassListDatasets{publicstaticvoidmain(String[]args){// TODO(developer): Replace these variables before running the sample.StringprojectId="MY_PROJECT_ID";listDatasets(projectId);}publicstaticvoidlistDatasets(StringprojectId){try{// Initialize client that will be used to send requests. This client only needs to be created// once, and can be reused for multiple requests.BigQuerybigquery=BigQueryOptions.getDefaultInstance().getService();Page<Dataset>datasets=bigquery.listDatasets(projectId,DatasetListOption.pageSize(100));if(datasets==null){System.out.println("Dataset does not contain any models");return;}datasets.iterateAll().forEach(dataset->System.out.printf("Success! Dataset ID: %s ",dataset.getDatasetId()));}catch(BigQueryExceptione){System.out.println("Project does not contain any datasets \n"+e.toString());}}}Node.js
Before trying this sample, follow theNode.js setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryNode.js API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
// Import the Google Cloud client libraryconst{BigQuery}=require('@google-cloud/bigquery');constbigquery=newBigQuery();asyncfunctionlistDatasets(){/** * TODO(developer): Uncomment the following lines before running the sample. */// const projectId = "my_project_id";// Lists all datasets in the specified project.// If projectId is not specified, this method will take// the projectId from the authenticated BigQuery Client.const[datasets]=awaitbigquery.getDatasets({projectId});console.log('Datasets:');datasets.forEach(dataset=>console.log(dataset.id));}PHP
Before trying this sample, follow thePHP setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryPHP API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
use Google\Cloud\BigQuery\BigQueryClient;/** * List all datasets in the given project * * @param string $projectId The project Id of your Google Cloud Project. */function list_datasets(string $projectId): void{ $bigQuery = new BigQueryClient([ 'projectId' => $projectId, ]); $datasets = $bigQuery->datasets(); foreach ($datasets as $dataset) { print($dataset->id() . PHP_EOL); }}Python
Before trying this sample, follow thePython setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryPython API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
fromgoogle.cloudimportbigquery# Construct a BigQuery client object.client=bigquery.Client()datasets=list(client.list_datasets())# Make an API request.project=client.projectifdatasets:print("Datasets in project{}:".format(project))fordatasetindatasets:print("\t{}".format(dataset.dataset_id))else:print("{} project does not contain any datasets.".format(project))Ruby
Before trying this sample, follow theRuby setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryRuby API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
What's next
To search and filter code samples for other Google Cloud products, see theGoogle Cloud sample browser.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.