From e863de3ab965a440432b1d410afe2fab22eea0e3 Mon Sep 17 00:00:00 2001 From: Eric Hare Date: Sat, 28 Oct 2023 07:14:44 -0700 Subject: [PATCH] Update README.md --- README.md | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1114e24c..332c45b1 100644 --- a/README.md +++ b/README.md @@ -34,12 +34,18 @@ Load the variables in and then create the client. This collections client can ma import os import sys +from dotenv import load_dotenv + from astrapy.db import AstraDB, AstraDBCollection from astrapy.ops import AstraDBOps +sys.path.append("../") + +load_dotenv() + # First, we work with devops -api_key = os.getenv("ASTRA_DB_APPLICATION_TOKEN") -astra_ops = AstraDBOps(api_key) +token = os.getenv("ASTRA_DB_APPLICATION_TOKEN") +astra_ops = AstraDBOps(token=token) # Define a database to create database_definition = { @@ -50,7 +56,7 @@ database_definition = { "region": os.getenv("ASTRA_DB_REGION", None), "capacityUnits": 1, "user": "example", - "password": api_key, + "password": token, "dbType": "vector", } @@ -58,6 +64,7 @@ database_definition = { create_result = astra_ops.create_database(database_definition=database_definition) # Grab the new information from the database +# NOTE: Your database will take some time to initialize! database_id = create_result["id"] database_region = astra_ops.get_database()[0]["info"]["region"] database_base_url = "apps.astra.datastax.com" @@ -66,7 +73,7 @@ database_base_url = "apps.astra.datastax.com" api_endpoint = f"https://{database_id}-{database_region}.{database_base_url}" # Initialize our vector db -astra_db = AstraDB(api_key=api_key, api_endpoint=api_endpoint) +astra_db = AstraDB(token=token, api_endpoint=api_endpoint) # Possible Operations astra_db.create_collection(collection_name="collection_test_delete", size=5) @@ -79,7 +86,7 @@ astra_db_collection = AstraDBCollection( ) # Or... astra_db_collection = AstraDBCollection( - collection_name="collection_test", api_key=api_key, api_endpoint=api_endpoint + collection_name="collection_test", token=token, api_endpoint=api_endpoint ) astra_db_collection.insert_one( @@ -91,7 +98,7 @@ astra_db_collection.insert_one( } ) -astra_db_collection.find_one({"name": "potato"}) +astra_db_collection.find_one({"name": "potato"}) # Not found astra_db_collection.find_one({"name": "Coded Cleats Copy"}) ```