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,
  spawn_api_options: APIOptions,
) -> Table[ROW]
Name Type Summary

name

str

The name of the table.

row_type

type

Optional. A formal specifier for the type checker. If provided, row_type must match the type hint specified in the assignment. For more information, see Typing support.

For an example, see Get a table and specify typing.

Default: Table[dict]

keyspace

str

Optional if you specified a working keyspace when you created the Database object. The keyspace containing the table.

Default: The working keyspace set when you created the Database object, if one was provided.

spawn_api_options

APIOptions

Optional. A complete or partial specification of the APIOptions to override the defaults inherited from the Database. Use this to customize the interaction of the Python client with the table. For example, you can change the serialization/deserialization options or default timeouts.

If APIOptions is passed together with a named parameter such as a timeout, the latter takes precedence over the corresponding spawn_api_options setting.

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
from astrapy.authentication import UsernamePasswordTokenProvider
from astrapy.constants import Environment

# Get an existing table
client = DataAPIClient(environment=Environment.HCD)
database = client.get_database(
    "API_ENDPOINT",
    token=UsernamePasswordTokenProvider("USERNAME", "PASSWORD"),
    keyspace="KEYSPACE_NAME",
)
table = database.get_table("TABLE_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
from astrapy.authentication import UsernamePasswordTokenProvider
from astrapy.constants import Environment


# 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(environment=Environment.HCD)
database = client.get_database(
    "API_ENDPOINT",
    token=UsernamePasswordTokenProvider("USERNAME", "PASSWORD"),
    keyspace="KEYSPACE_NAME",
)
table: Table[TableSchema] = database.get_table(
    "TABLE_NAME", row_type=TableSchema
)

Client reference

For more information, see the client reference.

Was this helpful?

Give Feedback

How can we improve the documentation?

© Copyright IBM Corporation 2026 | 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