Instantiate a client object (Python)

All Data API interactions through a client start with a DataAPIClient object. Once you have a DataAPIClient object, you can connect to a database and the perform CRUD operations on your data.

Creating a client object is an essential component of 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.

Result

Returns a DataAPIClient object that you can use to interact with the Data API.

Parameters

Name Type Summary

token

str | TokenProvider

Optional.

An application token, or an instance of TokenProvider. For more information about how to generate a token, see Get endpoint and token.

The username and password used to generate the token must be tied to a role that has sufficient permissions to perform the desired operations.

DataAPIClient objects aren’t specific to a database. Therefore, when you instantiate a client, you can omit this parameter and specify a token later with client.get_database() or client.get_admin().

environment

str

Optional. Specify the environment this client will work in.

Must be one of the values in astrapy.constants.Environment (or an equivalent string).

Default: Environment.PROD.

callers

list[tuple[str, str]]

Optional. Attaches special identifying entries to the User-Agent header for all HTTP requests issued to the Data API.

The full type of this parameter is Sequence[tuple[str | None, str | None]]. Each 2-item tuple in the sequence is a (caller_name, caller_version) pair: to form the final header, they will be joined and attached to the default, which is something like "astrapy/2.0.1".

api_options

APIOptions

Optional. A complete or partial specification of the APIOptions for the client. This allows you to customize the client interaction with the Data API. For example, you can use this parameter to change the timeout settings.

Examples

The following examples demonstrate how to instantiate a client.

Instantiate a client

from astrapy import DataAPIClient
from astrapy.constants import Environment

client = DataAPIClient(environment=Environment.HCD)

Instantiate a client and pass a token

from astrapy import DataAPIClient
from astrapy.authentication import UsernamePasswordTokenProvider
from astrapy.constants import Environment

client = DataAPIClient(
    token=UsernamePasswordTokenProvider("USERNAME", "PASSWORD"),
    environment=Environment.HCD,
)

Instantiate a client and specify options

from astrapy import DataAPIClient
from astrapy.api_options import (
    APIOptions,
    SerdesOptions,
    TimeoutOptions,
)
from astrapy.authentication import AWSEmbeddingHeadersProvider
from astrapy.constants import Environment

client = DataAPIClient(
    environment=Environment.HCD,
    api_options=APIOptions(
        timeout_options=TimeoutOptions(
            request_timeout_ms=15000,
            general_method_timeout_ms=30000,
            table_admin_timeout_ms=120000,
        ),
        serdes_options=SerdesOptions(
            custom_datatypes_in_reading=False,
            use_decimals_in_collections=True,
        ),
    ),
)

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