List data pipelines (Python SDK V2)

Updated at:

Calls ListDataPipelineConfigurations through OSS Python SDK V2 to list the data pipeline (DataPipeline) rules that meet the conditions in the current region by page.

Prerequisites

  • OSS Python SDK V2 is installed. You can run pip install alibabacloud-oss-v2 to install it.

  • Access credentials are configured by using environment variables. The example in this topic uses EnvironmentVariableCredentialsProvider to read credentials from the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables.

  • DataPipeline operations are forwarded by OSS to the underlying workflow service. Make sure that the source general-purpose bucket and the destination vector bucket are located in the same region.

Sample code

import argparse

import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.dataprocess as oss_dataprocess

parser = argparse.ArgumentParser(description="list data pipeline configurations sample")
parser.add_argument('--region', help='The region of the bucket.', required=True)
parser.add_argument('--endpoint', help='The endpoint of OSS.')
parser.add_argument('--max-results', type=int, help='The number of entries per page, 1~100.', default=10)
parser.add_argument('--prefix', help='The prefix of the data pipeline name.')


def main():
    args = parser.parse_args()

    credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
    cfg = oss.config.load_default()
    cfg.credentials_provider = credentials_provider
    cfg.region = args.region
    if args.endpoint is not None:
        cfg.endpoint = args.endpoint
    client = oss_dataprocess.Client(cfg)

    try:
        token = None
        total = 0
        while True:
            request = oss_dataprocess.models.ListDataPipelineConfigurationsRequest(
                max_results=args.max_results,
            )
            if args.prefix is not None:
                request.prefix = args.prefix
            if token is not None:
                request.next_token = token

            result = client.list_data_pipeline_configurations(request)

            # The pipeline list is in
            # data_pipeline_configurations.data_pipeline_configuration.
            container = result.data_pipeline_configurations
            configurations = container.data_pipeline_configuration if container else None
            for configuration in configurations or []:
                total += 1
                print(f'{configuration.data_pipeline_name}\t'
                      f'{configuration.status}\t'
                      f'{configuration.model_tier}')

            # An empty next_token means that all entries have been listed.
            token = result.next_token
            if not token:
                break

        print(f'status code: {result.status_code}, request id: {result.request_id}')
        print(f'total: {total}')
    except Exception as e:
        print(f'error:\n{e}')


if __name__ == '__main__':
    main()