API Enterprise SDK
Data Analysis Bot

Data Analysis Bot Enterprise SDK

The Data Analysis Bot SDK provides a conversational interface for exploring, cleaning, visualizing, and analyzing your database tables and local file datasets.

Under the hood, user queries are securely converted into Python code and executed on high-performance Pandas DataFrames using popular data science libraries including NumPy, Pandas, Scikit-learn, and Statsmodels.


Core Flow

Using the Data Analysis SDK consists of three basic phases:

  1. Instantiation: Specify the analysis model type.
  2. Data Integration: Establish a connection to file datasets or database clusters (PostgreSQL, Redshift, SQLite).
  3. Execution: Query in natural language to generate statistical summaries, insights, visualizations, and recommendations.

Getting Started

Installation

pip install aih[data-analysis]

Basic File Analysis Example

from aih import DataAnalysis
 
# 1. Create an instance
analysis = DataAnalysis(analysis_type="ml", api_key="openai_key")
 
# 2. Connect to files (CSV, Excel, or JSON)
analysis.get_data(
    db_type="files",
    db_config={
        "datasets": [
            {
                "name": "sales_data",
                "value": "./data/sales_transactions.csv"
            }
        ]
    }
)
 
# 3. Ask a question and retrieve statistical insights
result = analysis.ask("What are the top 5 highest selling product categories?")
print(result["insights"])

Database Integrations

Connect to enterprise data warehouses and relational databases:

1. Amazon Redshift Integration

redshift_config = {
    "host": "redshift-cluster-1.abcdef.us-east-1.redshift.amazonaws.com",
    "port": 5439,
    "database": "production_db",
    "user": "db_user",
    "password": "db_password",
    "schema": ["public", "analytics"], # Optional schemas to scan
    "tables": ["orders", "customers"]  # Optional tables to restrict search
}
 
analysis.get_data(
    db_type="redshift",
    db_config=redshift_config
)

2. PostgreSQL Integration

postgres_config = {
    "host": "db.mycompany.internal",
    "port": 5432,
    "database": "customer_data",
    "user": "postgres",
    "password": "secure_password"
}
 
analysis.get_data(
    db_type="postgres",
    db_config=postgres_config
)

3. SQLite Integration

analysis.get_data(
    db_type="sqlite",
    db_config={"db_path": "./data/local_cache.db"}
)

Running Analytics & Retrieving Plots

The ask method return dictionary contains four default outputs: visualisation, insights, recommendations, and tasks. You can control which outputs to build using the outputs parameter.

Generating Visualizations

Specify where to save the generated plot using plot_path:

result = analysis.ask(
    "Plot a correlation heatmap of numeric variables",
    outputs=["visualisation", "insights"],
    plot_path="./output/correlation_heatmap.png"
)
 
# Access the generated plot file path
print("Heatmap saved at:", result["visualisation"])

API Configuration Parameters

DataAnalysis Constructor Options

  • analysis_type string
    • "ml": Generates and executes Python code (Pandas, Scikit-learn).
    • "sql": Directly executes SQL query code on the database cluster.
    • "skip": Directly returns text-based insights without writing code.
  • api_key string
    Your OpenAI or Azure OpenAI model key.