Updated on 2024-03-06 GMT+08:00

Initializing the DLI Client

To use DLI Python SDK to access DLI, you need to initialize the DLI client. During DLI client initialization, you can use the AK/SK or token for authentication. For details about the dependencies and complete sample code, see Overview.

Example Code for AK/SK Authentication

  • Sample code
    1
    2
    3
    4
    5
    6
    7
    8
    def init_aksk_dli_client():
        auth_mode = 'aksk'
        region = 'xxx'
        project_id = 'xxxx'
        ak =  System.getenv("xxx_SDK_AK")//Access key ID
        sk = System.getenv("xxx_SDK_SK")//Key used together with the access key ID
        dli_client = DliClient(auth_mode=auth_mode, region=region, project_id=project_id,ak=ak, sk=sk)
        return dli_client
    
  • Parameter description and acquisition method
    • Parameter description
      • ak: Account access key
      • sk: Account secret access key

        Hard coding AKs and SKs or storing them in code in plaintext poses significant security risks. You are advised to store them in encrypted form in configuration files or environment variables and decrypt them when needed to ensure security.

        In this example, the AK and SK stored in the environment variables are used. Specify the environment variables xxx_SDK_AK and xxx_SDK_SK in the local environment first.

      • regionName: Region name
      • projectId: Project ID
    • You can perform the following operations to obtain the Access Keys, project ID, and Region:
      1. Log in to the management console.
      2. Hover the cursor on the username in the upper right corner and select My Credentials from the drop-down list.
      3. In the navigation pane on the left, choose Access Keys and click Create Access Key. Confirm that you want to proceed with the operation and click OK.
      4. On the displayed page, click Download. Open the credential file to obtain the AK/SK information.
      5. In the navigation pane on the left, choose API Credentials. In the Projects pane, locate project_id and obtain the region information.

Example Code for Token-based Authentication

  • Sample code
    1
    2
    3
    4
    5
    6
    7
    8
    9
    def init_token_dli_client():
       auth_mode = 'token'
        region = 'xxx'
        project_id = 'xxxx'
        account = 'xxx account'
        user = 'xxxx'
        password = 'xxxx'
        dli_client = DliClient(auth_mode=auth_mode, region=region, project_id=project_id,account=account, user=user, password=password)
        return dli_client
    
  • Parameter description
    • domainname: Name of the account to which the IAM user belongs
    • username: Username
    • password: User password
    • regionName: Region name
    • project_id: Project ID
    • Hard coding passwords or storing them in code in plaintext poses significant security risks. You are advised to store them in encrypted form in configuration files or environment variables and decrypt them when needed to ensure security.
    • You can change the endpoint in set mode. Run the following statement: dliInfo.setServerEndpoint(endpoint).