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

keyspace_admin_timeout_ms

int

Optional. A timeout, in milliseconds, to impose on the underlying API request. If not provided, the DataAPIDatabaseAdmin defaults apply.

This parameter is aliased as request_timeout_ms and timeout_ms for convenience.

Use the listKeyspaces method, which belongs to the DataAPIDbAdmin class.

Method signature
async listKeyspaces(
  options?: {
    timeout?: number | TimeoutDescriptor,
  }
): void
Name Type Summary

options

object

Optional. The options for this operation. See Properties of options for more details.

Properties of options
Name Type Summary

timeout

number | TimeoutDescriptor

Optional.

The timeout(s) to apply to this method. You can specify requestTimeoutMs and keyspaceAdminTimeoutMs.

Details about the timeout parameter

The TimeoutDescriptor object can contain these properties:

  • requestTimeoutMs (number): The maximum time, in milliseconds, that the client should wait for each underlying HTTP request.

    Default: The default value for the admin object. This default is 10 seconds unless you specified a different default when you initialized the DataAPIDbAdmin or DataAPIClient object.

  • keyspaceAdminTimeoutMs (number): The maximum time, in milliseconds, for keyspace admin operations like creating, dropping, and listing keyspaces.

    Default: The default value for the admin object. This default is 30 seconds unless you specified a different default when you initialized the DataAPIDbAdmin or DataAPIClient object.

If you specify a number instead of a TimeoutDescriptor object, that number will be applied to both requestTimeoutMs and keyspaceAdminTimeoutMs.

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.

Was this helpful?

Give Feedback

How can we improve the documentation?

© Copyright IBM Corporation 2025 | Privacy policy | Terms of use Manage Privacy Choices

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: Contact IBM