Connect with the Python client
Learn how to connect to a Serverless (Vector) database with the AstraPy client.
Prerequisites
-
An active Astra account
-
An active Serverless (Vector) database
-
An application token with the Database Administrator role
Install the Python client
Install the Python client with pip:
-
Verify that pip is version 23.0 or higher:
pip --version
-
If needed, upgrade pip:
python -m pip install --upgrade pip
-
Install the
astrapy
package. You must have Python 3.8 or higher.pip install astrapy
Connect to a vector-enabled Astra DB Serverless database
Create a file named quickstart.py
with the following content:
quickstart.py
import os
from astrapy import DataAPIClient
from astrapy.constants import VectorMetric
# Initialize the client and get a "Database" object
client = DataAPIClient(os.environ["ASTRA_DB_APPLICATION_TOKEN"])
database = client.get_database(os.environ["ASTRA_DB_API_ENDPOINT"])
print(f"* Database: {database.info().name}\n")
Run the script with python quickstart.py
.