List datasets (beta)

List datasets for a Google Cloud project.

Code sample

Python

To learn how to install and use the client library for Data Labeling Service, see Data Labeling Service client libraries. For more information, see the Data Labeling Service Python API reference documentation.

To authenticate to Data Labeling Service, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

def list_datasets(project_id):
    """Lists datasets for the given Google Cloud project."""
    from google.cloud import datalabeling_v1beta1 as datalabeling

    client = datalabeling.DataLabelingServiceClient()

    formatted_project_name = f"projects/{project_id}"

    response = client.list_datasets(request={"parent": formatted_project_name})
    for element in response:
        # The format of resource name:
        # project_id/{project_id}/datasets/{dataset_id}
        print(f"The dataset resource name: {element.name}\n")
        print(f"Display name: {element.display_name}")
        print(f"Description: {element.description}")
        print("Create time:")
        print(f"\tseconds: {element.create_time.timestamp_pb().seconds}")
        print(f"\tnanos: {element.create_time.timestamp_pb().nanos}")

What's next

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