Skip to content

• Python

1. Overview

Astra provides multiple services such as; Database and Streaming, with multiple Apis and interfaces. There are different frameworks and tools to connect to Astra depending on the Api interface you choose.

Pick the interface in the table below to get relevant instructions. In most cases, you will download a working sample. There are standalone examples designed to be as simple as possible. Please note that a Software developement KIT (SDK) is also available for you to reduce the amount of boilerplate code needed to get started. More information is here.

2. Interfaces List

Component Interface Description
Astra DB cql Main connection to Cassandra
Astra DB cql CQL exposes as stateless rest resources
Astra DB cql Use Cassandra as a Document DB
Astra DB cql Create tables and use generated CRUD
Astra DB cql CQL exposes through serialized protobuf
Astra Streaming cql Create Producer, Consumers, Subscriptions..
Astra Streaming cql Administrate your Pulsar cluster
Astra Core cql Manage Databases
Astra Core cql Manage users and roles
Astra Core cql Manage Streaming

3. CQL

3.1 Cassandra Drivers

ℹ️ Overview

These instructions are aimed at helping people connect to Astra DB programmatically using the DataStax Python driver.

📦 Prerequisites [ASTRA]

📦 Prerequisites [Development Environment]

You will need a recent version of Python 3. Visit https://www.python.org/downloads/ for more information on downloads and installation instructions for your machine architecture. To verify your Python install, run the following command:

python -V

With Python installed locally, you can now use Pip (Python's package manager) to install the DataStax Python driver.

pip install cassandra-driver

You can verify that the DataStax Python driver was installed successfully with this command:

python -c 'import cassandra; print (cassandra.__version__)'

📦 Setup Project

Create a new file and/or directory for your Python program.

mkdir python_project
cd python_project
touch testAstra.py

🖥️ Sample Code

To connect to an Astra DB cluster, you will need a secure token generated specifically for use with your Astra DB cluster.

mkdir ~/mySecureBundleDir
cd ~/mySecureBundleDir
mv ~/Downloads/secure-connect-bundle.zip .

Open up your favorite editor or IDE, and add 3 imports:

from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider
import sys

Next we will inject the connection parameters into the code. This can be done either by reading them as environment variables or passing them as command line arguments.

This example will be done using command line arguments:

clientID=sys.argv[1]
secret=sys.argv[2]
secureBundleLocation=sys.argv[3]

We'll also define the location of our secure connect bundle, and set that as a property in our cloud_config:

cloud_config= {
    'secure_connect_bundle': secureBundleLocation
}

Next, we'll define our authenticator and pass our credentials to it.

auth_provider = PlainTextAuthProvider(clientID, secret)

With all of that defined, we can build a cluster object and a connection:

cluster = Cluster(cloud=cloud_config, auth_provider=auth_provider)
session = cluster.connect()

With a connection made, we can run a simple query to return the name of the cluster from the system.local table:

row = session.execute("select cluster_name from system.local").one()
if row:
    print(row[0])
else:
    print("An error occurred.")

Running this code with arguments in the proper order should yield output similar to this:

python testAstra.py token "AstraCS:ASjPlHbTYourSecureTokenGoesHered3cdab53b" /Users/aaronploetz/mySecureBundleDir/secure-connect-bundle.zip

cndb

The complete code to this example can be found here.

3.2 Astra SDK

ℹ️ Overview

TODO

📦 Prerequisites [ASTRA]

TODO

📦 Prerequisites [Development Environment]

TODO

📦 Setup Project

TODO

🖥️ Sample Code

TODO

4. Stargate REST Api

4.1 Axios

ℹ️ Overview

TODO

📦 Prerequisites [ASTRA]

TODO

📦 Prerequisites [Development Environment]

TODO

📦 Setup Project

TODO

🖥️ Sample Code

TODO

4.2 Astra SDK

ℹ️ Overview

TODO

📦 Prerequisites [ASTRA]

TODO

📦 Prerequisites [Development Environment]

TODO

📦 Setup Project

TODO

🖥️ Sample Code

TODO

5. Stargate Document Api

5.1 Axios

ℹ️ Overview

TODO

📦 Prerequisites [ASTRA]

TODO

📦 Prerequisites [Development Environment]

TODO

📦 Setup Project

TODO

🖥️ Sample Code

TODO

5.2 Astra SDK

ℹ️ Overview

TODO

📦 Prerequisites [ASTRA]

TODO

📦 Prerequisites [Development Environment]

TODO

📦 Setup Project

TODO

🖥️ Sample Code

TODO

6 Stargate GraphQL

6.1 CQL First

ℹ️ Overview

TODO

📦 Prerequisites [ASTRA]

TODO

📦 Prerequisites [Development Environment]

TODO

📦 Setup Project

TODO

🖥️ Sample Code

TODO

6.2 GraphQL First

ℹ️ Overview

TODO

📦 Prerequisites [ASTRA]

TODO

📦 Prerequisites [Development Environment]

TODO

📦 Setup Project

TODO

🖥️ Sample Code

TODO

7. Stargate gRPC

7.1 Stargate Client

ℹ️ Overview

TODO

📦 Prerequisites [ASTRA]

TODO

📦 Prerequisites [Development Environment]

TODO

📦 Setup Project

TODO

🖥️ Sample Code

TODO

7.2 Astra SDK

ℹ️ Overview

TODO

📦 Prerequisites [ASTRA]

TODO

📦 Prerequisites [Development Environment]

TODO

📦 Setup Project

TODO

🖥️ Sample Code

TODO

8. Pulsar Client

8.1 Pulsar Client

ℹ️ Overview

TODO

📦 Prerequisites [ASTRA]

TODO

📦 Prerequisites [Development Environment]

TODO

📦 Setup Project

TODO

🖥️ Sample Code

TODO

8.2 Astra SDK

ℹ️ Overview

TODO

📦 Prerequisites [ASTRA]

TODO

📦 Prerequisites [Development Environment]

TODO

📦 Setup Project

TODO

🖥️ Sample Code

TODO

9. Pulsar Admin

10 Devops API Database

11 Devops API Organization

12 Devops API Streaming


Last update: 2022-09-02