Migrating Python driver
Complete the following procedure to migrate your existing DataStax Python driver to a version that is capable of connecting to DataStax Astra DB databases created using Astra DB.
-
Install the DataStax Python driver for Apache Cassandra:
pip install cassandra-driver
See the Python driver installation instructions for more information.
-
Verify that the DataStax Python driver for Apache Cassandra installed successfully:
python -c 'import cassandra; print cassandra.*version*'
The version number displays in the console output:
3.20.0
-
In your existing DataStax Python driver code, modify the connection code to use the Astra DB API. In the
cloud_config
parameter, include the path to the secure connect bundle for your Astra DB database (secure-connect-database_name.zip
), as shown in the following example.from cassandra.cluster import Cluster from cassandra.auth import PlainTextAuthProvider cloud_config= { 'secure_connect_bundle': '/path/to/secure-connect-database_name.zip' } auth_provider = PlainTextAuthProvider('clientId', 'clientSecret') cluster = Cluster(cloud=cloud_config, auth_provider=auth_provider) session = cluster.connect()
-
Run your Python script to connect to your Astra DB database:
python ./my_python_driver.py
If successful, the code builds, compiles, and connects to your Cassandra database.