Start with the DataAPIClient
When you create apps using the Data API clients for Python, TypeScript, and Java, your main entry point is the DataAPIClient
object.
If you haven’t already, install the client for your preferred language. See: Then proceed with the instructions in this topic. |
Get a client
Instantiate a client object. The client only needs a token, as it is not specific to a database.
-
Python
-
TypeScript
-
Java
View this topic in more detail on the API Reference.
client = DataAPIClient("TOKEN")
Returns:
DataAPIClient
- An instance of the client class.
Example response
DataAPIClient("AstraCS:aAbB...")
Parameters:
Name | Type | Summary |
---|---|---|
token |
|
An Access Token to the database. Example: |
Example:
from astrapy import DataAPIClient
client = DataAPIClient("TOKEN")
database0 = client.get_database_by_api_endpoint("API_ENDPOINT")
collection0 = database0.create_collection("movies", dimension=512)
collection0.insert_one({"title": "The Title"}, vector=...)
database1 = client.get_database("01234567-...")
database2 = client.get_database("01234567-...", region="us-east1")
admin = client.get_admin()
admin1 = client.get_admin(token=more_powerful_token_override)
database_iterator = admin.list_databases()
View this topic in more detail on the API Reference.
const client = new DataAPIClient('TOKEN');
Returns:
DataAPIClient
- An instance of the client class.
Parameters:
Name | Type | Summary |
---|---|---|
token |
|
An access token for the database, e.g. |
options? |
The options to use for the client, including defaults. |
Options (DataAPIClientOptions
):
Name | Type | Summary |
---|---|---|
Options related to the API requests the client makes. |
||
Allows default options for when spawning a Db instance. |
||
Allows default options for when spawning some Admin instance. |
Http Options (DataAPIHttpOptions
):
Name | Type | Summary |
---|---|---|
|
Whether to prefer HTTP/2 for requests to the Data API; if set to Note that the DevOps API always uses HTTP/1.1 regardless. |
|
|
The default maximum time in milliseconds to wait for a response from the server. Can be overridden per request. This does not mean the request will be cancelled after this time, but rather that the client will only wait for this time before considering the request to have timed out. |
|
Options specific to HTTP/1.1 requests (e.g. keepAlive and socket options). |
Example:
import { DataAPIClient } from '@datastax/astra-db-ts';
const client = new DataAPIClient('TOKEN');
const db1 = client.db('ENDPOINT');
const db2 = client.db('DB_ID', 'REGION');
(async function () {
const coll = await db1.createCollection('movies');
const admin1 = client.admin();
const admin2 = client.admin({ adminToken: 'STRONGER_TOKEN' });
console.log(await coll.insertOne({ name: 'Airplane!' }));
console.log(await admin1.listDatabases());
})();
// Default Initialization
DataAPIClient client = new DataAPIClient("TOKEN");
// Overriding default settings
DataAPIClient client = new DataAPIClient("TOKEN", DataAPIOptions.builder()
.withHttpConnectTimeout(20)
.withHttpRequestTimeout(20)
.build());
Returns:
DataAPIClient
- An instance of the client class.
Parameters:
Name | Type | Summary |
---|---|---|
token |
|
An Access Token to the database. Example: |
options |
A class wrapping the advanced configuration of the client such as as |
Example:
404: Not Found
Next steps
See the Databases reference topic.