PyPI Version Python License Docs

πŸš€ Talking Data

Talking Data is a lightweight, multi-provider AI Data Analysis library that performs SQL-based reasoning directly on your pandas.DataFrame using OpenAI, Groq, or Google Gemini models.

  • 🧩 Generates SQL queries from plain English questions
  • πŸš€ Executes them locally using DuckDB
  • 🧠 Summarizes results as insightful text or HTML
  • βš™ Installs missing dependencies automatically
No SQL experience required β€” just write a question, and open_analysis() handles everything.

Installation

pip install talking_data

Once installed, import it in your Python project:

from talking_data import open_analysis

⚑ Quickstart Example

from talking_data import open_analysis
import pandas as pd

df = pd.DataFrame({
    "region": ["East", "West", "North", "South"],
    "sales": [1200, 800, 950, 1100],
    "profit": [200, 100, 150, 180]
})

result = open_analysis(
    df=df,
    model_provider="openai",
    api_key="YOUR_API_KEY",
    question="Which region performs best by profit margin?",
    query_context="Profit margin = profit / sales * 100",
    log_level="detailed"
)

print("SQL Query:", result["sql_query"])
print(result["query_result"])
print("Insights:", result["plain_text_output"])

🧠 Examples by Provider

1️⃣ OpenAI Example

result = open_analysis(
    df=df,
    model_provider="openai",
    api_key="YOUR_OPENAI_API_KEY",
    question="Which region has the highest total sales?",
)
print(result["plain_text_output"])

2️⃣ Groq Example

result = open_analysis(
    df=df,
    model_provider="groq",
    api_key="YOUR_GROQ_API_KEY",
    question="Compare profit and sales correlation by region."
)
print(result["plain_text_output"])

3️⃣ Gemini Example

result = open_analysis(
    df=df,
    model_provider="gemini",
    api_key="YOUR_GEMINI_API_KEY",
    question="Find the top 2 regions by total sales."
)
print(result["plain_text_output"])
Each provider uses its own SDK and default model automatically. You can override the model name via the model parameter.

🧠 Example Output

Here’s what a typical open_analysis() call returns β€” a mix of plain text insights, SQL, and HTML output that you can render anywhere:

Plain Text Output

Region East has the highest profit margin of 16.7%, followed by South at 16.3%.

Generated SQL

SELECT region, SUM(profit)/SUM(sales)*100 AS margin 
            FROM df 
            GROUP BY region 
            ORDER BY margin DESC;

HTML Output

<section>
    <h3>Regional Profit Margin Insights</h3>
    <ul>
        <li>East region leads with a 16.7% margin</li>
        <li>South follows closely at 16.3%</li>
    </ul>
    </section>
πŸ’‘ The html_output field is ideal for embedding in dashboards or notebooks. The plain_text_output is optimized for chat or console interfaces. Both are auto-generated.

🧩 Supported Providers

ProviderDefault ModelSDK Dependency
🧠 OpenAIgpt-4oopenai
βš™ Groqllama-3.3-70b-versatilegroq
🌐 Google Geminigemini-2.0-flashgoogle-genai

The library detects and loads each SDK lazily at runtime β€” missing packages are installed automatically.

🧩 Function Reference

open_analysis(
    df: pd.DataFrame,
    model_provider: str = "openai",
    model: str = None,
    api_key: str = None,
    question: str = "Do a data analysis on the dataframe and give me insights?",
    temperature_one: float = 0.2,
    temperature_two: float = 0.7,
    max_completion_tokens: int = 1024,
    output_layer_context: str = None,
    query_context: str = None,
    log_level: str = "basic"
) -> dict

This function performs a two-stage process:

  1. SQL Generation β€” Converts your natural-language question into an executable SQL query.
  2. Insight Summarization β€” Executes the query on DuckDB and summarizes the result in both HTML and text formats.

🧾 Parameters

ParameterTypeDescription
dfpandas.DataFrameDataset to analyze.
model_providerstrProvider name: "gemini", "groq", or "openai".
modelstrOptional model override for fine-tuning provider behavior.
api_keystrAPI key for the selected provider.
questionstrNatural language query describing what to analyze.
query_contextstrOptional context (like KPI formula or definition).
temperature_onefloatControls creativity for SQL generation.
temperature_twofloatControls summarization creativity.
log_levelstr"none" | "basic" | "detailed" | "debug".

πŸ“€ Return Structure

{
  "provider": "openai",
  "model": "gpt-4o",
  "sql_query": "SELECT region, SUM(profit)/SUM(sales)*100 AS margin FROM df GROUP BY region ORDER BY margin DESC",
  "query_result": "",
  "html_output": "
...
", "plain_text_output": "East region has the highest profit margin (16.7%)", "logs": [...] }
You can access result["html_output"] for a formatted HTML summary suitable for embedding in web apps or notebooks.

πŸͺ΅ Logging Levels

  • none β€” No logs returned.
  • basic β€” Shows only essential steps.
  • detailed β€” Includes SQL and phase transitions.
  • debug β€” Includes tracebacks and full prompt data.

Logs are stored in result["logs"] as a list of messages.

🧩 FAQ

Q: Does it modify my DataFrame?
A: No, it registers it temporarily in DuckDB for querying.

Q: Can it work offline?
A: Not yet β€” all providers are cloud APIs.

Q: Do I need to install dependencies manually?
A: No, Talking Data installs them automatically when needed.

Q: Can I get HTML output?
A: Yes, via result["html_output"].

πŸ” Version History

VersionHighlights
0.9.0Improved logging, response behaviour
0.8.0Internal performance upgrades
0.7.0Enhanced summarization accuracy
0.5.0Added lazy import and unified provider handling
0.3.0Added Gemini and Groq support
0.0.0Initial OpenAI-only release

πŸͺͺ License

MIT License

Copyright (2025)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction...