This topic describes how to obtain a list of all existing collections by using the SDK for Python.
Prerequisites
A cluster is created. For more information, see Create a cluster.
An API key is obtained. For more information, see Manage API keys.
The SDK of the latest version is installed. For more information, see Install DashVector SDK.
API definition
Client.list() -> DashVectorResponseExample
You need to replace YOUR_API_KEY with your API key and YOUR_CLUSTER_ENDPOINT with the endpoint of your cluster in the sample code for the code to run properly.
import dashvector
client = dashvector.Client(
api_key='YOUR_API_KEY',
endpoint='YOUR_CLUSTER_ENDPOINT'
)
collections = client.list()
# Check whether the list method is successfully called.
if collections:
# View all collections.
for collection in collections:
print(collection)
# The length of collections.
print(len(collections))
# Check whether a collection exists.
print('YOUR_COLLECTION_NAME' in collections)
else:
# Display an error message if the operation fails.
print(collections)Request parameters
This operation does not have operation-specific request parameters.
Response parameters
A DashVectorResponse object is returned, which contains the operation result, as described in the following table.
Parameter | Type | Description | Example |
code | int | The returned status code. For more information, see Status codes. | 0 |
message | str | The returned message. | success |
request_id | str | The unique ID of the request. | 19215409-ea66-4db9-8764-26ce2eb5bb99 |
output | list[str] | The list of all collections. | ['my_collection1', 'my_collection2'] |