List keyspaces

Lists all keyspaces in a database.

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 an unordered list of strings.

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":[
      "quickstart_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/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
from astrapy.authentication import UsernamePasswordTokenProvider
from astrapy.constants import Environment
from astrapy.authentication import UsernamePasswordTokenProvider
from astrapy.constants import Environment

# Get a database
client = DataAPIClient(environment=Environment.HCD)
database = client.get_database(
    "API_ENDPOINT",
    token=UsernamePasswordTokenProvider("USERNAME", "PASSWORD"),
)

# Get an admin object
admin = database.get_database_admin()

# List keyspaces
keyspaces = admin.list_keyspaces()
print(keyspaces)
import {
  DataAPIClient,
  UsernamePasswordTokenProvider,
} from "@datastax/astra-db-ts";

// Get a database
const client = new DataAPIClient({ environment: "hcd" });
const database = client.db("API_ENDPOINT", {
  token: new UsernamePasswordTokenProvider("USERNAME", "PASSWORD"),
});

// Get an admin object
const admin = database.admin({ environment: "hcd" });

// List keyspaces
(async function () {
  const keyspaces = await admin.listKeyspaces();
  console.log(keyspaces);
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.DataAPIClients;
import com.datastax.astra.client.admin.DatabaseAdmin;
import com.datastax.astra.client.databases.Database;
import java.util.Set;

public class Example {

  public static void main(String[] args) {
    // Get a database
    DataAPIClient client = DataAPIClients.clientHCD("USERNAME", "PASSWORD");
    Database database = client.getDatabase("API_ENDPOINT", "KEYSPACE_NAME");

    // Get an admin object
    DatabaseAdmin admin = database.getDatabaseAdmin();

    // List keyspaces
    Set<String> keyspaces = admin.listKeyspaceNames();
    System.out.println(keyspaces);
  }
}
curl -sS -L -X POST "API_ENDPOINT/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?

© 2025 DataStax | 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: +1 (650) 389-6000, info@datastax.com