Get a database object

When using a client, most Data API interactions require you to connect to a database through a DataAPIClient object.

Connecting to a database is an essential component of most Data API client scripts. For more information, see Get started with the Data API.

For more information about the Data API client hierarchy, see Python client usage, TypeScript client usage, and Java client usage.

Result

Returns a Database object that you can use to perform CRUD operations on your database

Parameters

Use the get_database method, which belongs to the astrapy.DataAPIClient class.

Method signature
python
get_database(
    api_endpoint: str,
    *,
    token: str | TokenProvider,
    keyspace: str,
    spawn_api_options: APIOptions,
) -> Database
Name Type Summary

api_endpoint

str

A database API endpoint URL, such as https://DATABASE_ID-REGION.apps.astra.datastax.com.

token

str | TokenProvider

Optional. An application token for a database, in the form of an "AstraCS:…​" string, or an instance of TokenProvider.

The token should have sufficient permissions to perform the desired operations.

If you specified a token when instantiating the DataAPIClient, that token will be overridden.

keyspace

str

Optional. Specify the working keyspace. You can override this in downstream methods such as use_keyspace, get_collection, create_collection, get_table, create_table.

Default: "default_keyspace".

spawn_api_options

APIOptions

Optional. A complete or partial specification of the APIOptions.

This overrides the defaults inherited from the Data API client. This allows you to customize the interaction with the Data API. For example, you can use this parameter to change the timeout settings.

Examples

The following examples demonstrate how to connect to a database.

python
from astrapy import DataAPIClient

client = DataAPIClient()
database = client.get_database("API_ENDPOINT", token="APPLICATION_TOKEN")

Client reference

For more information, see the client reference.

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