Dark Mode

Use the unified DataStax Python driver to connect to your DataStax Astra DB database and begin building your own application.

DataStax recommends using the unified DataStax Python driver.If you have an existing Apache Cassandra or DataStax Enterprise (DSE) Python driver, migrate the driver to a version that is capable of connecting to Astra DB databases.

Prerequisites

  • Download and install a supported Python version. Python 2.7, 3.4, 3.5 and 3.6 are supported.
  • Download the secure connect bundle to obtain connection credentials for your Astra DB database.

Procedure

  • Install the DataStax Python driver.
  • Verify that the DataStax Python driver installed successfully:
  • Create a connect_database.py file in the main directory for your Python project.
  • Copy the following connection code into the connect_database.py file.
  • After the connection code, add the following code to connect-database.py .This code creates a Cluster instance to connect to your Astra DB database, runs a CQL query, and prints the output to the console.As the name suggests, you will typically have one instance of https://docs.datastax.com/en/developer/python-dse-driver/latest/api/dse/cluster/#dse.cluster.Cluster[Cluster, window="_blank"] for each Cassandra cluster you want to interact with.
  • Save and close the connect_database.py file.
  • Run connect_database.py .