Help Center> Data Lake Insight> SDK Reference> Python SDK> Initializing the DLI Client

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 perform authentication using the AK/SK or token. The sample code is as follows:

Example Code for AK/SK Authentication

1
2
3
4
5
6
7
8
def init_aksk_dli_client():
    auth_mode = 'aksk'
    region = 'cn-north-1'
    project_id = 'xxxx'
    ak = 'xxxx'
    sk = 'xxxx'
    dli_client = DliClient(auth_mode=auth_mode, region=region, project_id=project_id,ak=ak, sk=sk)
    return dli_client

You can perform the following operations to obtain the Access Keys, project ID, and Region:

  1. Register with and log in to the management console.
  2. Click the username in the upper right corner and select My Credentials from the drop-down list.
  3. On the My Credentials page:
    • Click Access Keys to view the created access key.
    • Click Projects to view the project ID and Region.

Example Code for Token-based Authentication

1
2
3
4
5
6
7
8
9
def init_token_dli_client():
   auth_mode = 'token'
    region = 'cn-north-1'
    project_id = 'xxxx'
    account = 'huaweicloud_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

You can change the endpoint in set mode. Run the following statement: dliInfo.setServerEndpoint(endpoint).