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.

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("The dataset resource name: {}\n".format(element.name))
        print("Display name: {}".format(element.display_name))
        print("Description: {}".format(element.description))
        print("Create time:")
        print("\tseconds: {}".format(element.create_time.timestamp_pb().seconds))
        print("\tnanos: {}".format(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.