List keyspaces
Lists all keyspaces in a database.
|
You need an application token with permission to interact with the target database, such as the Database Administrator role. For more information, see Get endpoint and token. |
Result
-
Python
-
TypeScript
-
Java
-
curl
Returns the keyspace names as an unordered list of strings.
Returns a promise that resolves to the keyspace names as a list of strings, with the default keyspace first and the remaining keyspaces in any order.
Returns the keyspace names as a Set of strings.
Returns the keyspace names as an unordered list of strings in the status.keyspaces field of the response.
Example response:
{
"status": {
"keyspaces":[
"default_keyspace",
"another_keyspace"
]
}
}
Parameters
-
Python
-
TypeScript
-
Java
-
curl
Use the list_keyspaces method, which belongs to the astrapy.DataAPIDatabaseAdmin class.
Method signature
list_keyspaces(
*,
keyspace_admin_timeout_ms: int,
request_timeout_ms: int,
timeout_ms: int,
) -> None
| Name | Type | Summary |
|---|---|---|
|
|
Optional.
A timeout, in milliseconds, to impose on the underlying API request.
If not provided, the This parameter is aliased as |
Use the listKeyspaces method, which belongs to the DataAPIDbAdmin class.
Method signature
async listKeyspaces(
options?: {
timeout?: number | TimeoutDescriptor,
}
): void
| Name | Type | Summary |
|---|---|---|
|
|
Optional.
The options for this operation. See Properties of |
| Name | Type | Summary |
|---|---|---|
|
|
Optional. The timeout(s) to apply to this method.
You can specify Details about the
|
Use the listKeyspaceNames method, which belongs to the com.datastax.astra.client.admin.DatabaseAdmin class.
Method signature
Set<String> listKeyspaceNames()
This method does not accept any parameters.
Use the findKeyspaces command.
Command signature
curl -sS -L -X POST "API_ENDPOINT/api/json/v1" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"findKeyspaces": {}
}'
This command does not accept any options.
Examples
The following examples demonstrate how to list keyspaces.
List keyspaces
-
Python
-
TypeScript
-
Java
-
curl
from astrapy import DataAPIClient
client = DataAPIClient("TOKEN")
db_admin = client.get_admin().get_database_admin("https://01234567-...")
db_admin.list_keyspaces()
# ['default_keyspace']
db_admin.create_keyspace("that_other_one")
# this 'create_keyspace' method call takes a few seconds ...
db_admin.list_keyspaces()
# ['default_keyspace', 'that_other_one']
import { DataAPIClient } from '@datastax/astra-db-ts'
// Spawn an AstraDbAdmin instance
const admin = new DataAPIClient('TOKEN').admin();
const dbAdmin = admin.dbAdmin('ENDPOINT');
(async function () {
// ['default_keyspace']
console.log(await dbAdmin.listKeyspaces());
await dbAdmin.createKeyspace('that_other_one');
// ['default_keyspace', 'that_other_one']
console.log(await dbAdmin.listKeyspaces());
})();
package com.datastax.astra.client.database_admin;
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.admin.AstraDBAdmin;
import com.datastax.astra.client.admin.DatabaseAdmin;
import java.util.Set;
import java.util.UUID;
public class ListKeyspaces {
public static void main(String[] args) {
DataAPIClient client = new DataAPIClient("TOKEN");
// Accessing admin providing a new token possibly with stronger permissions
AstraDBAdmin admin = client.getAdmin("SUPER_USER_TOKEN");
DatabaseAdmin dbAdmin = admin.getDatabaseAdmin(UUID.fromString("DATABASE_ID"));
// List available keyspaces
Set<String> names = dbAdmin.listKeyspaceNames();
}
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"findKeyspaces": {}
}'
Client reference
-
Python
-
TypeScript
-
Java
-
curl
For more information, see the client reference.
For more information, see the client reference.
For more information, see the client reference.
Client reference documentation is not applicable for HTTP.