• 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¶
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]
- You should have an Astra account
- You should Create an Astra Database
- You should Have an Astra Token
- You should Download your Secure bundle
📦 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:
With Python installed locally, you can now use Pip (Python's package manager) to install the DataStax Python driver.
You can verify that the DataStax Python driver was installed successfully with this command:
📦 Setup Project
Create a new file and/or directory for your Python program.
🖥️ Sample Code
To connect to an Astra DB cluster, you will need a secure token generated specifically for use with your Astra DB cluster.
Open up your favorite editor or IDE, and add 3 imports:
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:
We'll also define the location of our secure connect bundle, and set that as a property in our cloud_config
:
Next, we'll define our authenticator and pass our credentials to it.
With all of that defined, we can build a cluster object and a connection:
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
📦 Prerequisites [ASTRA]
📦 Prerequisites [Development Environment]
📦 Setup Project
🖥️ Sample Code
4. Stargate REST Api¶
4.1 Axios¶
ℹ️ Overview
📦 Prerequisites [ASTRA]
📦 Prerequisites [Development Environment]
📦 Setup Project
🖥️ Sample Code
4.2 Astra SDK¶
ℹ️ Overview
📦 Prerequisites [ASTRA]
📦 Prerequisites [Development Environment]
📦 Setup Project
🖥️ Sample Code
5. Stargate Document Api¶
5.1 Axios¶
ℹ️ Overview
📦 Prerequisites [ASTRA]
📦 Prerequisites [Development Environment]
📦 Setup Project
🖥️ Sample Code
5.2 Astra SDK¶
ℹ️ Overview
📦 Prerequisites [ASTRA]
📦 Prerequisites [Development Environment]
📦 Setup Project
🖥️ Sample Code
6 Stargate GraphQL¶
6.1 CQL First¶
ℹ️ Overview
📦 Prerequisites [ASTRA]
📦 Prerequisites [Development Environment]
📦 Setup Project
🖥️ Sample Code
6.2 GraphQL First¶
ℹ️ Overview
📦 Prerequisites [ASTRA]
📦 Prerequisites [Development Environment]
📦 Setup Project
🖥️ Sample Code
7. Stargate gRPC¶
7.1 Stargate Client¶
ℹ️ Overview
📦 Prerequisites [ASTRA]
📦 Prerequisites [Development Environment]
📦 Setup Project
🖥️ Sample Code
7.2 Astra SDK¶
ℹ️ Overview
📦 Prerequisites [ASTRA]
📦 Prerequisites [Development Environment]
📦 Setup Project
🖥️ Sample Code
8. Pulsar Client¶
8.1 Pulsar Client¶
ℹ️ Overview
📦 Prerequisites [ASTRA]
📦 Prerequisites [Development Environment]
📦 Setup Project
🖥️ Sample Code
8.2 Astra SDK¶
ℹ️ Overview
📦 Prerequisites [ASTRA]
📦 Prerequisites [Development Environment]
📦 Setup Project
🖥️ Sample Code