Skip to content
github-actions[bot] edited this page Oct 3, 2025 · 10 revisions

AnswerRocket Python Client

Welcome to the AnswerRocket Python Client documentation! This library provides programmatic access to AnswerRocket's generative AI analytics platform.

What is AnswerRocket?

AnswerRocket is a generative AI analytics platform for enterprise data exploration. It provides:

  • Natural language interface for business intelligence queries
  • AI agents for instant data insights and visualizations
  • Automated reporting and analytics workflows

Quick Start

Installation

pip install answerrocket-client

Basic Usage

from answer_rocket import AnswerRocketClient

# Initialize the client
arc = AnswerRocketClient(
    url='https://your-answerrocket-instance.com',
    token='<your_api_token>'
)

# Test connection
arc.can_connect()

Authentication

You can authenticate using either direct parameters or environment variables (recommended):

export AR_URL="https://your-instance.com"
export AR_TOKEN="your_api_token"
# Client will automatically use environment variables
arc = AnswerRocketClient()

API tokens are available through the AnswerRocket UI for authenticated users.

Key Components

The AnswerRocket client provides access to several key modules:

  • client - Main client class for initialization and connection
  • data - SQL/RQL execution, dataset operations, AI-powered SQL generation
  • chat - Natural language questions to AI copilots
  • config - Configuration and artifact management
  • output - Output and visualization building
  • skill - Skill management
  • llm - Language model operations

Common Use Cases

Execute SQL Queries

database_id = "my_database_id"
sql = "SELECT sum(revenue) FROM sales WHERE year = 2024"

result = arc.data.execute_sql_query(database_id, sql, limit=100)

if result.success:
    print(result.df)  # pandas DataFrame
else:
    print(f"Error: {result.error}")

Ask Natural Language Questions

copilot_id = "your_copilot_id"
question = "What were our top selling products last quarter?"

entry = arc.chat.ask_question(copilot_id, question)
print(entry)

AI-Powered SQL Generation

database_id = "my_database_id"
question = "Show me revenue by region for Q4"

result = arc.data.run_sql_ai(database_id, question)

if result.success:
    print(f"Generated SQL: {result.sql}")
    print(result.df)

Language Model Interactions

messages = [
    {"role": "system", "content": "You are a data analyst assistant."},
    {"role": "user", "content": "What is the average of 150, 12, 200, 54, 24, and 32?"}
]

success, reply = arc.llm.completion(messages=messages)

if success:
    content = reply["choices"][0]["message"]["content"]
    print(content)

Streaming Responses

def display_streaming_result(chunk):
    print(chunk, end="", flush=True)

success, reply = arc.llm.completion(
    messages=messages,
    stream_callback=display_streaming_result
)

API Reference

For detailed documentation of all classes, methods, and parameters, see the API Reference.

Requirements

  • Python >= 3.10.7
  • Dependencies: sgqlc, pandas>=1.5.1, typing-extensions

Support

For issues and questions:

Notes

  • When running outside of an AnswerRocket installation (e.g., during development), make sure to set the OpenAI API key:
    import os
    os.environ['OPENAI_API_KEY'] = 'your_openai_key'
Clone this wiki locally