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

str

An Access Token to the database. Example: "AstraCS:aAbB…​".

Example:

from astrapy import DataAPIClient
client = DataAPIClient("TOKEN")
database0 = client.get_database("API_ENDPOINT")
collection0 = database0.create_collection("movies", dimension=5)
collection0.insert_one({
    "title": "The Title",
    "$vector": [0.1, 0.3, -0.7, 0.9, -0.1],
})
database_by_id = client.get_database("01234567-...")
database_by_id_region = 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

string

An access token for the database, e.g. 'AstraCS:aAbB…​'.

options?

DataAPIClientOptions

The options to use for the client, including defaults.

Name Type Summary

httpOptions?

DataAPIHttpOptions

Options related to the API requests the client makes.

dbOptions?

DbSpawnOptions

Allows default options for when spawning a Db instance.

adminOptions?

AdminSpawnOptions

Allows default options for when spawning some Admin instance.

Http Options (DataAPIHttpOptions):

Name Type Summary

preferHttp2?

boolean

Whether to prefer HTTP/2 for requests to the Data API; if set to false, HTTP/1.1 will be used instead.

Note that the DevOps API always uses HTTP/1.1 regardless.

maxTimeMs?

number

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.

http1?

DataAPIHttp1Options

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

String

An Access Token to the database. Example: "AstraCS:aAbB…​".

options

DataAPIOptions

A class wrapping the advanced configuration of the client such as as HttpClient settings (timeouts…​).

Example:

404: Not Found

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

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