Create a keyspace
Creates a new keyspace in a database.
Keyspaces are used to store collections and tables in Astra DB Serverless.
|
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
Creates the specified keyspace.
Does not return anything.
Creates the specified keyspace.
Returns a promise that resolves once the operation completes.
Creates the specified keyspace.
Does not return anything.
Creates the specified keyspace.
Returns 201 Created.
Parameters
-
Python
-
TypeScript
-
Java
-
curl
Use the create_keyspace method, which belongs to the astrapy.DataAPIDatabaseAdmin class.
Method signature
create_keyspace(
name: str,
*,
wait_until_active: bool,
update_db_keyspace: bool,
keyspace_admin_timeout_ms: int,
request_timeout_ms: int,
timeout_ms: int,
**kwargs: Any,
) -> None
| Name | Type | Summary |
|---|---|---|
|
|
The name of the keyspace to create. If a keyspace with the name already exists, a new keyspace isn’t created, and the command succeeds.
|
|
|
Optional. Whether to wait for the database to become active again before returning. If false, the method returns immediately after issuing the creation request, but you cannot work with the database until it becomes active again. Default: true |
|
|
Optional.
Whether to set the working keyspace of the |
|
|
Optional.
A timeout, in milliseconds, to impose on the underlying API request.
If not provided, the This parameter is aliased as |
Use the createKeyspace method, which belongs to the DataAPIDbAdmin class.
Method signature
async createKeyspace(
keyspace: string,
options?: {
blocking?: boolean,
updateDbKeyspace?: boolean,
timeout?: number | TimeoutDescriptor,
}
): void
| Name | Type | Summary |
|---|---|---|
|
|
The name of the keyspace to create. If a keyspace with the name already exists, a new keyspace isn’t created, and the command succeeds.
|
|
|
Optional.
The options for this operation. See Properties of |
| Name | Type | Summary |
|---|---|---|
|
|
Optional. Whether to wait for the database to become active again before returning. If false, the method returns immediately after issuing the creation request, but you cannot work with the database until it becomes active again. Default: true |
|
|
Optional.
Whether to set the working keyspace of the |
|
|
Optional. The timeout(s) to apply to this method.
You can specify Details about the
|
Use the createKeyspace method, which belongs to the com.datastax.astra.client.admin.DatabaseAdmin class.
Method signature
void createKeyspace(String keyspaceName)
void createKeyspace(KeyspaceDefinition keyspaceDefinition)
void createKeyspace(
KeyspaceDefinition keyspaceDefinition,
CreateKeyspaceOptions options
)
| Name | Type | Summary |
|---|---|---|
|
|
The name of the keyspace to create.
|
|
|
The keyspace name and optionally replication factors.
See Methods of |
|
|
Optional.
The options for this operation. See Methods of |
| Method | Parameters | Summary |
|---|---|---|
|
|
The name of the keyspace to create. |
|
|
Specifies the options for keyspace replication across database nodes using a simple strategy. Keyspace replication is not applicable for Astra DB Serverless. |
|
|
Specifies the options for keyspace replication across database nodes using a network topology strategy. Keyspace replication is not applicable for Astra DB Serverless. |
| Method | Parameters | Summary |
|---|---|---|
|
|
Optional.
Whether to set the working keyspace of the Default: false |
|
|
Optional. Whether the command should silently succeed even if a keyspace with the given name already exists and no new keyspace was created. Default: true |
Use the DevOps API to create a keyspace, as demonstrated in Examples. This operation is a POST request that includes the new keyspace name as a path parameter.
Keyspace names must follow these rules:
-
Must start with a letter or number
-
Can contain letters, numbers, and underscores
-
Cannot exceed 48 characters.
-
Cannot be the reserved words
dseorsystem -
Must be unique within the database
Examples
The following examples demonstrate how to create a keyspace.
Create a keyspace
-
Python
-
TypeScript
-
Java
-
curl
from astrapy import DataAPIClient
# Get a database
client = DataAPIClient()
database = client.get_database(
"API_ENDPOINT",
token="APPLICATION_TOKEN",
)
# Get an admin object
admin = database.get_database_admin()
# Create a keyspace
admin.create_keyspace("KEYSPACE_NAME")
import { DataAPIClient } from "@datastax/astra-db-ts";
// Get a database
const client = new DataAPIClient();
const database = client.db("API_ENDPOINT", {
token: "APPLICATION_TOKEN",
});
// Get an admin object
const admin = database.admin();
// Create a keyspace
(async function () {
await admin.createKeyspace("KEYSPACE_NAME");
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.admin.DatabaseAdmin;
import com.datastax.astra.client.databases.Database;
public class Example {
public static void main(String[] args) {
// Get a database
Database database = new DataAPIClient("APPLICATION_TOKEN").getDatabase("API_ENDPOINT");
// Get an admin object
DatabaseAdmin admin = database.getDatabaseAdmin();
// Create a keyspace
admin.createKeyspace("KEYSPACE_NAME");
}
}
curl -sS -L -X POST "https://api.astra.datastax.com/v2/databases/DATABASE_ID/keyspaces/KEYSPACE_NAME" \
--header "Authorization: Bearer APPLICATION_TOKEN" \
--header "Content-Type: application/json"
Create a keyspace and set it as the working keyspace for the database
-
Python
-
TypeScript
-
Java
-
curl
from astrapy import DataAPIClient
# Get a database
client = DataAPIClient()
database = client.get_database(
"API_ENDPOINT",
token="APPLICATION_TOKEN",
)
# Get an admin object
admin = database.get_database_admin()
# Create a keyspace
admin.create_keyspace("KEYSPACE_NAME", update_db_keyspace=True)
import { DataAPIClient } from "@datastax/astra-db-ts";
// Get a database
const client = new DataAPIClient();
const database = client.db("API_ENDPOINT", {
token: "APPLICATION_TOKEN",
});
// Get an admin object
const admin = database.admin();
// Create a keyspace
(async function () {
await admin.createKeyspace("KEYSPACE_NAME", { updateDbKeyspace: true });
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.admin.DatabaseAdmin;
import com.datastax.astra.client.databases.Database;
import com.datastax.astra.client.databases.commands.options.CreateKeyspaceOptions;
import com.datastax.astra.client.databases.definition.keyspaces.KeyspaceDefinition;
public class Example {
public static void main(String[] args) {
// Get a database
Database database = new DataAPIClient("APPLICATION_TOKEN").getDatabase("API_ENDPOINT");
// Get an admin object
DatabaseAdmin admin = database.getDatabaseAdmin();
// Create a keyspace
KeyspaceDefinition definition = new KeyspaceDefinition().name("KEYSPACE_NAME");
CreateKeyspaceOptions keyspaceOptions = new CreateKeyspaceOptions().updateDBKeyspace(true);
admin.createKeyspace(definition, keyspaceOptions);
}
}
This option only applies to the clients.
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.