Skip to main content

AI-powered data analysis for structured and unstructured data. Query PDF, Word, CSV, Excel with natural language.

Project description

QuerySUTRA

Natural language to SQL. Upload PDF, CSV, Excel — ask questions in plain English.

pip install QuerySUTRA

Usage

from sutra import SUTRA

sutra = SUTRA(api_key="your-openai-key")
sutra.upload("data.pdf")
result = sutra.ask("How many employees are in each state?")
print(result.data)

Upload Any Format

sutra.upload("report.pdf")       # PDF — AI extracts entities into related tables
sutra.upload("sales.csv")        # CSV
sutra.upload("data.xlsx")        # Excel
sutra.upload("records.json")     # JSON

import pandas as pd
df = pd.DataFrame({"name": ["Alice", "Bob"], "score": [95, 87]})
sutra.upload(df, name="students")

Ask Questions

result = sutra.ask("Show top 5 products by revenue")
print(result.sql)         # Generated SQL
print(result.data)        # pandas DataFrame

# With charts
result = sutra.ask("Sales by region", viz=True)        # Auto-picks best chart
result = sutra.ask("Revenue split", viz="pie")          # Specific chart type
result = sutra.ask("Price over time", viz="line")       # pie | bar | line | scatter

Explore Data

sutra.tables()              # List all tables
sutra.schema()              # Show columns and types
sutra.peek()                # Preview rows
sutra.peek("sales", 10)    # Specific table

Direct SQL

result = sutra.sql("SELECT * FROM products WHERE price > 100")

Export

sutra.save_to_mysql("localhost", "root", "password", "my_db")
sutra.export_db("backup.json", format="json")

How It Works

Upload File → AI extracts entities into related tables (with foreign keys)
            → Stored in SQLite
            → Ask questions in English
            → AI generates SQL with proper JOINs
            → Results as DataFrame + optional chart

Smart JOINs — QuerySUTRA detects foreign key relationships between tables (person_id → people.id) and generates proper JOIN queries automatically. When you ask "Who is the DevOps engineer?", it knows to JOIN work_experience with people to get the name.

Smart Charts — Auto-picks the right visualization. Few categories → pie. Many categories → bar. Two numbers → scatter. Or specify: viz="pie".

Troubleshooting

After installing or upgrading, if your Jupyter notebook still uses the old version:

# Option 1: Restart kernel and re-import
# Kernel → Restart Kernel

# Option 2: Force reload without restarting
import importlib
import sutra
import sutra.sutra
importlib.reload(sutra.sutra)
from sutra.sutra import SUTRA

Check which version is loaded:

import sutra
print(sutra.__version__, sutra.__file__)

Install Extras

pip install QuerySUTRA[mysql]       # MySQL export
pip install QuerySUTRA[embeddings]  # Semantic similarity
pip install QuerySUTRA[all]         # Everything

API

Method Description
SUTRA(api_key, db) Initialize. db defaults to "sutra.db"
.upload(file_or_df, name) Upload from file path or DataFrame
.ask(question, viz) Natural language query. viz=True or "pie"/"bar"/"line"/"scatter"
.sql(query) Direct SQL
.tables() List tables
.schema() Show structure
.peek(table, n) Preview rows
.save_to_mysql(host, user, pw, db) Export to MySQL
.export_db(path, format) Export SQLite or JSON
.close() Close connection

QueryResult: result.success · result.sql · result.data · result.viz · result.error

License

MIT — Aditya Batta

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

querysutra-0.6.2.tar.gz (45.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

querysutra-0.6.2-py3-none-any.whl (47.3 kB view details)

Uploaded Python 3

File details

Details for the file querysutra-0.6.2.tar.gz.

File metadata

  • Download URL: querysutra-0.6.2.tar.gz
  • Upload date:
  • Size: 45.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for querysutra-0.6.2.tar.gz
Algorithm Hash digest
SHA256 e36045966d57f96eda84d304142a1660ba35cb875f0e6a9573ff5c108353ec21
MD5 77e30bb6b1e35dbcb764c2b8dcfd20b6
BLAKE2b-256 06089a9a96ce45267e95b79efaa1227a459559d6fd82ec8cdb62587054e7227a

See more details on using hashes here.

File details

Details for the file querysutra-0.6.2-py3-none-any.whl.

File metadata

  • Download URL: querysutra-0.6.2-py3-none-any.whl
  • Upload date:
  • Size: 47.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for querysutra-0.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6f7c1dc3a5552bdc9c9816c379bf1787be28d53fe1b02b00aea4406e9ed8d60e
MD5 f4d2982de6313a1f61f8a4502c720b50
BLAKE2b-256 1f29dc84ad4544dfbca3a47424ddd852c03730fec94c42bcaf5a48a4c34e8e11

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page