Query a data pipeline (Python SDK V2)

Updated at:

Calls GetDataPipelineConfiguration through OSS Python SDK V2 to query the complete configuration and the current running state of a specified data pipeline (DataPipeline) rule.

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="get data pipeline configuration 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('--data-pipeline-name', help='The name of the data pipeline.', required=True)


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:
        result = client.get_data_pipeline_configuration(
            oss_dataprocess.models.GetDataPipelineConfigurationRequest(
                data_pipeline_name=args.data_pipeline_name,
            ))
        print(f'status code: {result.status_code}, request id: {result.request_id}')

        # The configuration is in result.configuration.
        configuration = result.configuration
        print(f'name: {configuration.data_pipeline_name}')
        # Ready means initializing, Running means processing data, and Paused means paused.
        print(f'status: {configuration.status}')
        print(f'phase: {configuration.phase}')
        print(f'description: {configuration.data_pipeline_description}')
        # A model_tier of standard means AI VibeStudio is used, and an empty value means
        # Alibaba Cloud Model Studio is used for vectorization.
        print(f'model tier: {configuration.model_tier}')
        print(f'create time: {configuration.create_time}')
        print(f'role: {configuration.data_pipeline_role}')

        # The source configuration is in the sources list, from which you can read the
        # source bucket and prefix.
        for source in configuration.sources:
            print(f'input bucket: {source.input_bucket}')
            if source.filter_configuration is not None:
                print(f'prefix set: {source.filter_configuration.prefix_set}')
    except Exception as e:
        print(f'error:\n{e}')


if __name__ == '__main__':
    main()