Cassio

0.1.10 · active · verified Thu Apr 16

Cassio is a framework-agnostic Python library designed for seamless integration of Apache Cassandra® with ML/LLM/genAI workloads. It provides utilities for interacting with Cassandra as a vector store, managing chat memory, and caching LLM responses, often serving as the core engine for higher-level frameworks like LangChain or LlamaIndex. The library is currently in an alpha release (v0.1.10) and has a moderately active release cadence, with occasional breaking changes expected.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize Cassio to connect to DataStax Astra DB using environment variables for the database ID and application token. This is the recommended approach for cloud-based GenAI workloads. It includes error handling for missing credentials during initialization.

import os
import cassio

# Set these environment variables for Astra DB connection
# ASTRA_DB_ID = "your_astra_database_id"
# ASTRA_DB_APPLICATION_TOKEN = "your_astra_application_token"
# ASTRA_DB_KEYSPACE = "your_astra_keyspace" (optional)

# Initialize Cassio with Astra DB credentials
try:
    cassio.init(
        database_id=os.environ.get('ASTRA_DB_ID'),
        token=os.environ.get('ASTRA_DB_APPLICATION_TOKEN'),
        keyspace=os.environ.get('ASTRA_DB_KEYSPACE', 'default_keyspace')
    )
    print("Cassio initialized successfully with Astra DB.")

    # Example: Verify session and keyspace (optional)
    session = cassio.get_session()
    keyspace = cassio.get_keyspace()
    if session and keyspace:
        print(f"Connected to keyspace: {keyspace}")
    else:
        print("Failed to retrieve session or keyspace after initialization.")

except ValueError as e:
    print(f"Cassio initialization failed: {e}")
    print("Please ensure ASTRA_DB_ID and ASTRA_DB_APPLICATION_TOKEN environment variables are set.")
except Exception as e:
    print(f"An unexpected error occurred during Cassio initialization: {e}")

view raw JSON →