本文由簡體中文內容自動轉碼而成。阿里雲不保證此自動轉碼的準確性、完整性及時效性。本文内容請以簡體中文版本為準。

建立Client

更新時間:2024-07-13 00:21

本文介紹如何通過Python SDK建立一個DashVector Client。

說明

通過DashVector Client可串連DashVector服務端,進行Collection相關操作。

前提條件

介面定義

Python
dashvector.Client(
    api_key: str,
    endpoint: str,
    protocol: dashvector.DashVectorProtocol = dashvector.DashVectorProtocol.GRPC,
    timeout: float = 10.0
) -> Client

使用樣本

說明

需要使用您的api-key替換樣本中的YOUR_API_KEY、您的Cluster Endpoint替換樣本中的YOUR_CLUSTER_ENDPOINT,代碼才能正常運行。

Python
import dashvector

client = dashvector.Client(
    api_key='YOUR_API_KEY',
    endpoint='YOUR_CLUSTER_ENDPOINT'
)

# 判斷client是否建立成功
if client:
    print('create client success!')

# 等同於下列代碼
# from dashvector import DashVectorCode
# if client.code == DashVectorCode.Success:
#     print('create client success!')

入參描述

參數

類型

預設值

說明

api_key

str

-

api-key

endpoint

str

-

Cluster的Endpoint

protocol(可選)

DashVectorProtocol

DashVectorProtocol.GRPC

通訊協定,DashVectorProtocol.GRPC、DashVectorProtocol.HTTP

timeout(可選)

float

10.0

逾時時間(單位:秒),-1 代表不逾時。

說明
  1. endpoint參數,可在控制台Cluster詳情中查看。

  2. protocol參數,建議使用預設值DashVectorProtocol.GRPC,可獲得更高的效能體驗。

出參描述

說明

返回結果為Client對象,Client對象中可擷取本次操作結果資訊,如下表所示。

欄位

類型

描述

樣本

code

int

傳回值,參考返回狀態代碼說明

0

message

str

返回訊息

success

request_id

str

請求唯一id

19215409-ea66-4db9-8764-26ce2eb5bb99

  • 本頁導讀 (1, M)
  • 前提條件
  • 介面定義
  • 使用樣本
  • 入參描述
  • 出參描述
文檔反饋
phone Contact Us