π 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
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"])
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>
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
| Provider | Default Model | SDK Dependency |
|---|---|---|
| π§ OpenAI | gpt-4o | openai |
| β Groq | llama-3.3-70b-versatile | groq |
| π Google Gemini | gemini-2.0-flash | google-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:
- SQL Generation β Converts your natural-language question into an executable SQL query.
- Insight Summarization β Executes the query on DuckDB and summarizes the result in both HTML and text formats.
π§Ύ Parameters
| Parameter | Type | Description |
|---|---|---|
df | pandas.DataFrame | Dataset to analyze. |
model_provider | str | Provider name: "gemini", "groq", or "openai". |
model | str | Optional model override for fine-tuning provider behavior. |
api_key | str | API key for the selected provider. |
question | str | Natural language query describing what to analyze. |
query_context | str | Optional context (like KPI formula or definition). |
temperature_one | float | Controls creativity for SQL generation. |
temperature_two | float | Controls summarization creativity. |
log_level | str | "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": [...]
}
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
| Version | Highlights |
|---|---|
| 0.9.0 | Improved logging, response behaviour |
| 0.8.0 | Internal performance upgrades |
| 0.7.0 | Enhanced summarization accuracy |
| 0.5.0 | Added lazy import and unified provider handling |
| 0.3.0 | Added Gemini and Groq support |
| 0.0.0 | Initial 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...