Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
erichare authored Oct 28, 2023
1 parent 9aec100 commit e863de3
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -50,14 +56,15 @@ database_definition = {
"region": os.getenv("ASTRA_DB_REGION", None),
"capacityUnits": 1,
"user": "example",
"password": api_key,
"password": token,
"dbType": "vector",
}

# Create the database
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"
Expand All @@ -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)
Expand All @@ -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(
Expand All @@ -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"})
```

Expand Down

0 comments on commit e863de3

Please sign in to comment.