List table metadata
Gets information about the tables in a keyspace.
|
Ready to write code? See the examples for this method to get started. If you are new to the Data API, check out the quickstart. |
Result
-
Python
-
TypeScript
-
Go
-
Java
-
C#
-
curl
Returns an unordered list of ListTableDescriptor objects that describe each table.
Returns a promise that resolves to an unordered list of FullTableInfo objects that describe each table.
|
The Go client is in preview. For more information, see astra-db-go. |
Returns an unordered slice of TableDescriptor structs that describe each table.
Returns an unordered list of TableDescriptor objects that describe each table.
Returns IEnumerable<TableInfo>, where each TableInfo object describes a table.
The status.tables field in the response describes each table.
Example response:
{
"status": {
"tables": [
{
"name": "customers",
"definition": {
"columns": {
"order_date": {
"type": "timestamp"
},
"preferences": {
"type": "map",
"keyType": "text",
"valueType": "text"
},
"is_active": {
"type": "boolean"
},
"user_id": {
"type": "uuid"
},
"name": {
"type": "text"
},
"login_attempts": {
"type": "set",
"valueType": "int"
},
"photo": {
"type": "blob"
},
"salary": {
"type": "decimal"
},
"order_id": {
"type": "uuid"
},
"age": {
"type": "int"
},
"tags": {
"type": "list",
"valueType": "text"
}
},
"primaryKey": {
"partitionBy": [
"user_id"
],
"partitionSort": {
"order_id": 1,
"order_date": -1
}
}
}
}
]
}
}
Parameters
-
Python
-
TypeScript
-
Go
-
Java
-
C#
-
curl
Use the list_tables method, which belongs to the astrapy.Database class.
Method signature
list_tables(
*,
keyspace: str,
table_admin_timeout_ms: int,
request_timeout_ms: int,
timeout_ms: int,
) -> list[ListTableDescriptor]
| Name | Type | Summary |
|---|---|---|
|
|
Optional. The keyspace to inspect. For an example, see List table metadata and specify the keyspace. Default: The database’s working keyspace. |
|
|
Optional.
A timeout, in milliseconds, for the underlying HTTP request.
If not provided, the |
Use the listTables method, which belongs to the Db class.
Method signature
async listTables(
options?: {
nameOnly?: false,
keyspace?: string,
timeout?: number | TimeoutDescriptor,
},
): TableDescriptor[]
| Name | Type | Summary |
|---|---|---|
|
|
Optional.
The options for this operation.
See Properties of |
| Name | Type | Summary |
|---|---|---|
|
|
Must be |
|
|
Optional. The keyspace to inspect. For an example, see List table metadata and specify the keyspace. Default: The database’s working keyspace. |
|
|
Optional. A timeout to impose on the underlying API request. |
|
The Go client is in preview. For more information, see astra-db-go. |
Use the ListTables method, which belongs to the Db type.
Method signature
func (d *Db) ListTables(
ctx context.Context,
opts ...options.ListTablesOption
) ([]results.TableDescriptor, error)
| Name | Type | Summary |
|---|---|---|
|
|
The context for the operation. |
|
Optional.
A builder to generate options for this operation.
See Methods of the |
| Method | Summary |
|---|---|
|
Optional. The keyspace to inspect. Default: The database’s working keyspace. |
|
Optional. General API options for this operation, including the timeout. |
Use the listTables method, which belongs to the com.datastax.astra.client.databases.Database class.
Method signature
List<TableDescriptor> listTables()
List<TableDescriptor> listTables(ListTablesOptions listTableOptions)
| Name | Type | Summary |
|---|---|---|
|
Optional. The options for this operation, including the keyspace and timeouts. |
Use the ListTablesAsync method, which belongs to the Database class.
You can also use ListTables, which is the synchronous version of the method.
Method signature
public Task<IEnumerable<TableInfo>> ListTablesAsync(
ListTablesOptions options = null
);
| Name | Type | Summary |
|---|---|---|
|
Optional. General API options for this operation, including the keyspace and timeout. For more information and examples, see Customize API interaction. |
Use the listTables command.
Command signature
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"listTables": {
"options": {
"explain": true
}
}
}'
| Name | Type | Summary |
|---|---|---|
|
|
Must be |
Examples
The following examples demonstrate how to list table metadata.
List table metadata
-
Python
-
TypeScript
-
Go
-
Java
-
C#
-
curl
from astrapy import DataAPIClient
# Get a database
client = DataAPIClient()
database = client.get_database(
"API_ENDPOINT", token="APPLICATION_TOKEN"
)
# List table metadata
result = database.list_tables()
print(result)
import { DataAPIClient } from "@datastax/astra-db-ts";
// Get a database
const client = new DataAPIClient();
const database = client.db("API_ENDPOINT", {
token: "APPLICATION_TOKEN",
});
// List table metadata
(async function () {
const result = await database.listTables();
console.log(result);
})();
|
The Go client is in preview. For more information, see astra-db-go. |
package main
import (
"context"
"encoding/json"
"fmt"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
)
func main() {
ctx := context.Background()
// Get a database
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
// List table metadata
tables, err := database.ListTables(ctx)
if err != nil {
log.Fatal(err)
}
output, err := json.Marshal(tables)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(output))
}
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.databases.Database;
import com.datastax.astra.client.tables.definition.TableDescriptor;
import java.util.List;
public class Example {
public static void main(String[] args) {
// Get a database
Database database = new DataAPIClient("APPLICATION_TOKEN").getDatabase("API_ENDPOINT");
// List table metadata
List<TableDescriptor> result = database.listTables();
System.out.println(result);
}
}
using System.Text.Json;
using DataStax.AstraDB.DataApi;
namespace Examples;
public class Program
{
static async Task Main()
{
// Get a database
var client = new DataAPIClient();
var database = client.GetDatabase(
"API_ENDPOINT",
"APPLICATION_TOKEN"
);
// List table metadata
var result = await database.ListTablesAsync();
Console.WriteLine(JsonSerializer.Serialize(result));
}
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"listTables": {
"options": {
"explain": true
}
}
}'
List table metadata and specify the keyspace
By default, this method uses the working keyspace of your database. If you want to use a different keyspace, you must specify the keyspace.
-
Python
-
TypeScript
-
Go
-
Java
-
C#
-
curl
from astrapy import DataAPIClient
# Get a database
client = DataAPIClient()
database = client.get_database(
"API_ENDPOINT", token="APPLICATION_TOKEN"
)
# List table metadata
result = database.list_tables(keyspace="KEYSPACE_NAME")
print(result)
import { DataAPIClient } from "@datastax/astra-db-ts";
// Get a database
const client = new DataAPIClient();
const database = client.db("API_ENDPOINT", {
token: "APPLICATION_TOKEN",
});
// List table metadata
(async function () {
const result = await database.listTables({
keyspace: "KEYSPACE_NAME",
});
console.log(result);
})();
|
The Go client is in preview. For more information, see astra-db-go. |
package main
import (
"context"
"encoding/json"
"fmt"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
)
func main() {
ctx := context.Background()
// Get a database
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
// List table metadata
tables, err := database.ListTables(
ctx,
options.ListTables().SetKeyspace("KEYSPACE_NAME"),
)
if err != nil {
log.Fatal(err)
}
output, err := json.Marshal(tables)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(output))
}
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.databases.Database;
import com.datastax.astra.client.tables.commands.options.ListTablesOptions;
import com.datastax.astra.client.tables.definition.TableDescriptor;
import java.util.List;
public class Example {
public static void main(String[] args) {
// Get a database
Database database = new DataAPIClient("APPLICATION_TOKEN").getDatabase("API_ENDPOINT");
// List table metadata
ListTablesOptions options = new ListTablesOptions().keyspace("KEYSPACE_NAME");
List<TableDescriptor> result = database.listTables(options);
System.out.println(result);
}
}
using System.Text.Json;
using DataStax.AstraDB.DataApi;
using DataStax.AstraDB.DataApi.Core;
namespace Examples;
public class Program
{
static async Task Main()
{
// Get a database
var client = new DataAPIClient();
var database = client.GetDatabase(
"API_ENDPOINT",
"APPLICATION_TOKEN"
);
// List table metadata
var result = await database.ListTablesAsync(
new ListTablesOptions() { Keyspace = "KEYSPACE_NAME" }
);
Console.WriteLine(JsonSerializer.Serialize(result));
}
}
This option has no literal equivalent in HTTP. Instead, you always specify the keyspace in the path.
Client reference
-
Python
-
TypeScript
-
Go
-
Java
-
C#
-
curl
For more information, see the client reference.
For more information, see the client reference.
|
The Go client is in preview. For more information, see astra-db-go. |
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.