Skip to content

Commit

Permalink
Merge pull request #76 from datastax/readme-update
Browse files Browse the repository at this point in the history
Cleanup the README to match the latest API interface
  • Loading branch information
erichare committed Nov 6, 2023
2 parents c866065 + 1c9ebae commit 9d6754b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 38 deletions.
41 changes: 4 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,55 +20,25 @@ Setup your Astra client
Create a .env file with the appropriate values, or use the 'astra' cli to do the same.

```bash
ASTRA_DB_KEYSPACE="<keyspace>"
ASTRA_DB_APPLICATION_TOKEN="<AstraCS:...>"
ASTRA_DB_REGION="<region>"
ASTRA_DB_ID=<db_id>
ASTRA_DB_API_ENDPOINT="<https://...>"
```

Load the variables in and then create the client. This collections client can make non-vector and vector calls, depending on the call configuration.

```python
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
# Grab the Astra token and api endpoint from the environment
token = os.getenv("ASTRA_DB_APPLICATION_TOKEN")
astra_ops = AstraDBOps(token=token)

# Define a database to create
database_definition = {
"name": "vector_test",
"tier": "serverless",
"cloudProvider": "GCP",
"keyspace": os.getenv("ASTRA_DB_KEYSPACE", "default_keyspace"),
"region": os.getenv("ASTRA_DB_REGION", None),
"capacityUnits": 1,
"user": "example",
"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"

# Build the endpoint URL:
api_endpoint = f"https://{database_id}-{database_region}.{database_base_url}"
api_endpoint = os.getenv("ASTRA_DB_API_ENDPOINT")

# Initialize our vector db
astra_db = AstraDB(token=token, api_endpoint=api_endpoint)
Expand Down Expand Up @@ -118,11 +88,8 @@ Ensure you provide all required environment variables:

```bash
export ASTRA_DB_ID="..."
export ASTRA_DB_REGION="..."
export ASTRA_DB_APPLICATION_TOKEN="..."
export ASTRA_DB_KEYSPACE="..."
export ASTRA_CLIENT_ID="..."
export ASTRA_CLIENT_SECRET="..."
export ASTRA_DB_API_ENDPOINT="..."
```

then you can run:
Expand Down
2 changes: 1 addition & 1 deletion astrapy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
__version__ = "0.5.3"
__version__ = "0.5.4"

0 comments on commit 9d6754b

Please sign in to comment.