Get a database object (Python)
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 (Python).
For more information about the Data API client hierarchy, see Python client internals, TypeScript client internals, Go client internals, Java client internals, and C# client internals.
Parameters
Use the get_database method, which belongs to the astrapy.DataAPIClient class.
Method signature
get_database(
api_endpoint: str,
*,
token: str | TokenProvider,
keyspace: str,
spawn_api_options: APIOptions,
) -> Database
| Name | Type | Summary |
|---|---|---|
|
|
A database API endpoint URL, such as |
|
|
Optional.
An application token for a database, in the form of an The token should have sufficient permissions to perform the desired operations. If you specified a token when instantiating the |
|
|
Optional.
Specify the working keyspace.
This keyspace is used for all downstream operations unless you later override it with a method such as Default: default_keyspace |
|
|
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.
from astrapy import DataAPIClient
client = DataAPIClient()
database = client.get_database(
"API_ENDPOINT", token="APPLICATION_TOKEN"
)
Client reference
For more information, see the client reference.