Get a table (Python)
Gets a reference to a table for use with the Data API clients.
|
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
Returns a Table object that corresponds to the specified table name.
This method returns a Table object even for tables that don’t exist.
Unless you specify the row_type parameter, the table is typed as Table[dict].
For more information, see Typing support.
Parameters
Use the get_table method, which belongs to the astrapy.Database class.
Method signature
get_table(
name: str,
*,
row_type: type[Any],
keyspace: str,
embedding_api_key: str | EmbeddingHeadersProvider,
spawn_api_options: APIOptions,
) -> Table[ROW]
| Name | Type | Summary |
|---|---|---|
|
|
The name of the table. |
|
|
Optional.
A formal specifier for the type checker.
If provided, For an example, see Get a table and specify typing. Default: |
|
|
Optional. The keyspace containing the table. For an example, see Get a table and specify the keyspace. Default: The working keyspace for the database.
This is |
|
|
Optional. This only applies to tables that have a vector column with a vectorize embedding provider integration. Use this option to provide the embedding provider API key directly with headers instead of using an API key in the Astra DB KMS. The API key is sent to the Data API for every operation on the table. It is useful when a vectorize integration is configured but no credentials are stored, or when you want to override the stored credentials. For more information, see Manage embedding provider integrations for vectorize. You can use this authentication method only if all affected columns use the same embedding provider. If you use an AWS embedding provider, the |
|
Optional.
A complete or partial specification of the APIOptions to override the defaults inherited from the If |
Examples
The following examples demonstrate how to get a table.
Get a table
The following example uses untyped documents or rows, but you can define a client-side type for your collection to help statically catch errors. For examples, see Typing support.
from astrapy import DataAPIClient
# Get an existing table
client = DataAPIClient()
database = client.get_database(
"API_ENDPOINT", token="APPLICATION_TOKEN"
)
table = database.get_table("TABLE_NAME")
Get a table 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.
The following example uses untyped documents or rows, but you can define a client-side type for your collection to help statically catch errors. For examples, see Typing support.
from astrapy import DataAPIClient
# Get an existing table
client = DataAPIClient()
database = client.get_database(
"API_ENDPOINT", token="APPLICATION_TOKEN"
)
table = database.get_table(
"TABLE_NAME",
keyspace="KEYSPACE_NAME",
)
Get a table and specify typing
Use the row_type parameter to specify typing for the row.
The value of row_type should be a subclass of TypedDict.
If you don’t specify the row_type parameter, the table is typed as Table[dict].
from datetime import date
from typing import Dict, Optional, Set, TypedDict
from astrapy import DataAPIClient, Table
# Define the typing
class TableSchema(TypedDict):
title: str
author: str
number_of_pages: int
rating: float
genres: Set[str]
metadata: Dict[str, str]
is_checked_out: bool
due_date: Optional[date]
# Get an existing table
client = DataAPIClient()
database = client.get_database(
"API_ENDPOINT", token="APPLICATION_TOKEN"
)
table: Table[TableSchema] = database.get_table(
"TABLE_NAME", row_type=TableSchema
)
Client reference
For more information, see the client reference.