QuerySUTRA 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. querysutra-0.1.0/LICENSE +21 -0
  2. querysutra-0.1.0/MANIFEST.in +8 -0
  3. querysutra-0.1.0/PKG-INFO +385 -0
  4. querysutra-0.1.0/QuerySUTRA.egg-info/PKG-INFO +385 -0
  5. querysutra-0.1.0/QuerySUTRA.egg-info/SOURCES.txt +36 -0
  6. querysutra-0.1.0/QuerySUTRA.egg-info/dependency_links.txt +1 -0
  7. querysutra-0.1.0/QuerySUTRA.egg-info/requires.txt +11 -0
  8. querysutra-0.1.0/QuerySUTRA.egg-info/top_level.txt +2 -0
  9. querysutra-0.1.0/README.md +348 -0
  10. querysutra-0.1.0/examples/quickstart.py +126 -0
  11. querysutra-0.1.0/examples/sutra_usage_guide.ipynb +451 -0
  12. querysutra-0.1.0/examples/usage_guide.ipynb +419 -0
  13. querysutra-0.1.0/pyproject.toml +44 -0
  14. querysutra-0.1.0/requirements.txt +18 -0
  15. querysutra-0.1.0/setup.cfg +4 -0
  16. querysutra-0.1.0/setup.py +41 -0
  17. querysutra-0.1.0/sutra/__init__.py +25 -0
  18. querysutra-0.1.0/sutra/cache_manager.py +86 -0
  19. querysutra-0.1.0/sutra/clear_cache.py +6 -0
  20. querysutra-0.1.0/sutra/core.py +301 -0
  21. querysutra-0.1.0/sutra/data_loader.py +145 -0
  22. querysutra-0.1.0/sutra/database_manager.py +196 -0
  23. querysutra-0.1.0/sutra/direct_query.py +95 -0
  24. querysutra-0.1.0/sutra/feedback.py +41 -0
  25. querysutra-0.1.0/sutra/feedback_matcher.py +74 -0
  26. querysutra-0.1.0/sutra/nlp_processor.py +144 -0
  27. querysutra-0.1.0/sutra/schema_embeddings.py +213 -0
  28. querysutra-0.1.0/sutra/schema_generator.py +53 -0
  29. querysutra-0.1.0/sutra/sutra.py +562 -0
  30. querysutra-0.1.0/sutra/sutra_client.py +431 -0
  31. querysutra-0.1.0/sutra/sutra_core.py +342 -0
  32. querysutra-0.1.0/sutra/sutra_simple.py +678 -0
  33. querysutra-0.1.0/sutra/visualizer.py +169 -0
  34. querysutra-0.1.0/tests/test_modules.py +0 -0
  35. querysutra-0.1.0/tests/test_sutra.py +76 -0
  36. querysutra-0.1.0/utils/__init__.py +0 -0
  37. querysutra-0.1.0/utils/file_utils.py +0 -0
  38. querysutra-0.1.0/utils/text_utils.py +0 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Your Name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,8 @@
1
+ include README.md
2
+ include LICENSE
3
+ include requirements.txt
4
+ recursive-include examples *.ipynb *.py
5
+ recursive-include sutra *.py
6
+ global-exclude __pycache__
7
+ global-exclude *.py[co]
8
+ global-exclude .DS_Store
@@ -0,0 +1,385 @@
1
+ Metadata-Version: 2.4
2
+ Name: QuerySUTRA
3
+ Version: 0.1.0
4
+ Summary: Natural Language to SQL Query System with Visualization
5
+ Home-page: https://github.com/adityabatta/sutra
6
+ Author: Aditya Batta
7
+ Author-email: Aditya Batta <b05aditya@gmail.com>
8
+ Project-URL: Homepage, https://github.com/adityabatta/sutra
9
+ Project-URL: Repository, https://github.com/adityabatta/sutra
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
13
+ Classifier: Topic :: Database
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Requires-Python: >=3.8
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: openai>=1.12.0
24
+ Requires-Dist: pandas>=2.2.0
25
+ Requires-Dist: numpy>=1.24.3
26
+ Requires-Dist: plotly
27
+ Requires-Dist: matplotlib>=3.7.1
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest>=7.4.0; extra == "dev"
30
+ Requires-Dist: pytest-cov; extra == "dev"
31
+ Requires-Dist: black; extra == "dev"
32
+ Requires-Dist: flake8; extra == "dev"
33
+ Dynamic: author
34
+ Dynamic: home-page
35
+ Dynamic: license-file
36
+ Dynamic: requires-python
37
+
38
+ # ๐Ÿš€ SUTRA - Simple Unified Tool for Relational Analysis
39
+
40
+ **Natural Language to SQL Query System with Auto-Visualization**
41
+
42
+ A single-file Python library that converts your questions into SQL queries and visualizes the results automatically.
43
+
44
+ ---
45
+
46
+ ## โœจ What You Get
47
+
48
+ โœ… **One file** - Everything in `sutra.py`
49
+ โœ… **Natural language** - Ask questions in plain English
50
+ โœ… **Multiple formats** - CSV, Excel, JSON, SQL, DataFrames
51
+ โœ… **Direct SQL** - No API cost option
52
+ โœ… **Auto visualization** - Charts with one parameter
53
+ โœ… **Interactive mode** - Ask user for viz choice
54
+ โœ… **Jupyter ready** - Perfect for notebooks
55
+
56
+ ---
57
+
58
+ ## ๐Ÿ“ฆ Installation
59
+
60
+ ```bash
61
+ pip install sutra
62
+ ```
63
+
64
+ ---
65
+
66
+ ## ๐ŸŽฏ Complete Workflow (9 Steps)
67
+
68
+ ### Step 1: Install
69
+ ```bash
70
+ pip install sutra
71
+ ```
72
+
73
+ ### Step 2: Import
74
+ ```python
75
+ from sutra import SUTRA
76
+ ```
77
+
78
+ ### Step 3: Enter API Key
79
+ ```python
80
+ sutra = SUTRA(api_key="your-openai-api-key")
81
+ ```
82
+
83
+ ### Step 4: Upload Data (Any Format!)
84
+ ```python
85
+ # CSV
86
+ sutra.upload("data.csv")
87
+
88
+ # Excel
89
+ sutra.upload("data.xlsx")
90
+
91
+ # DataFrame
92
+ import pandas as pd
93
+ df = pd.DataFrame({'sales': [100, 200], 'region': ['North', 'South']})
94
+ sutra.upload(df, name="sales_data")
95
+
96
+ # JSON
97
+ sutra.upload("data.json")
98
+ ```
99
+
100
+ ### Step 5: Database Auto-Created
101
+ Database is automatically created and managed!
102
+
103
+ ### Step 6: Direct SQL (No API Cost!)
104
+ ```python
105
+ result = sutra.sql("SELECT * FROM sales_data WHERE sales > 150")
106
+ print(result.data)
107
+ ```
108
+
109
+ ### Step 7: Natural Language Queries
110
+ ```python
111
+ result = sutra.ask("What are total sales by region?")
112
+ print(result.data)
113
+ ```
114
+
115
+ ### Step 8: With Visualization
116
+ ```python
117
+ # Set viz=True for automatic charts
118
+ result = sutra.ask("Show sales by region", viz=True)
119
+
120
+ # Or ask user interactively
121
+ result = sutra.interactive("Show sales by region")
122
+ # Prompts: "Do you want visualization? (yes/no):"
123
+ ```
124
+
125
+ ### Step 9: Works in Jupyter Notebooks!
126
+ See `SUTRA_Complete_Guide.ipynb` for step-by-step examples.
127
+
128
+ ---
129
+
130
+ ## ๐Ÿ“– Quick Examples
131
+
132
+ ### Basic Usage
133
+ ```python
134
+ from sutra import SUTRA
135
+
136
+ # Initialize
137
+ sutra = SUTRA(api_key="sk-...")
138
+
139
+ # Upload data
140
+ sutra.upload("sales.csv")
141
+
142
+ # Ask questions
143
+ result = sutra.ask("What are total sales?")
144
+ print(result.data)
145
+ ```
146
+
147
+ ### With Visualization
148
+ ```python
149
+ result = sutra.ask("Show top 10 products by revenue", viz=True)
150
+ # Chart appears automatically!
151
+ print(result.data)
152
+ ```
153
+
154
+ ### Interactive Mode
155
+ ```python
156
+ result = sutra.interactive("What are sales trends?")
157
+ # Asks: "Do you want visualization? (yes/no):"
158
+ ```
159
+
160
+ ### Direct SQL (No API Cost)
161
+ ```python
162
+ result = sutra.sql("SELECT region, SUM(sales) FROM data GROUP BY region")
163
+ print(result.data)
164
+ ```
165
+
166
+ ### Export Results
167
+ ```python
168
+ result = sutra.ask("Show all data")
169
+ sutra.export(result.data, "output.csv")
170
+ sutra.export(result.data, "output.xlsx", format="excel")
171
+ ```
172
+
173
+ ---
174
+
175
+ ## ๐Ÿ“Š Jupyter Notebook Guide
176
+
177
+ Open `SUTRA_Complete_Guide.ipynb` for a complete step-by-step tutorial with:
178
+ - All 9 steps explained
179
+ - Multiple examples
180
+ - Interactive queries
181
+ - Visualization options
182
+ - Export examples
183
+
184
+ ---
185
+
186
+ ## ๐Ÿ› ๏ธ API Reference
187
+
188
+ ### Main Methods
189
+
190
+ ```python
191
+ # Initialize
192
+ sutra = SUTRA(api_key="...", db="mydb.db")
193
+
194
+ # Upload data
195
+ sutra.upload(data, name="table_name") # data = file path or DataFrame
196
+
197
+ # View database
198
+ sutra.tables() # List all tables
199
+ sutra.schema() # Show schema
200
+ sutra.peek(n=10) # Preview data
201
+
202
+ # Query with SQL
203
+ result = sutra.sql("SELECT ...", viz=False)
204
+
205
+ # Query with natural language
206
+ result = sutra.ask("question", viz=False, table="table_name")
207
+
208
+ # Interactive query
209
+ result = sutra.interactive("question") # Prompts for viz choice
210
+
211
+ # Export
212
+ sutra.export(data, "file.csv", format="csv") # or "excel", "json"
213
+
214
+ # Close
215
+ sutra.close()
216
+ ```
217
+
218
+ ### QueryResult Object
219
+
220
+ ```python
221
+ result.success # bool
222
+ result.sql # Generated SQL query
223
+ result.data # pandas DataFrame
224
+ result.viz # Visualization object
225
+ result.error # Error message (if failed)
226
+ ```
227
+
228
+ ---
229
+
230
+ ## ๐ŸŽจ Features
231
+
232
+ | Feature | Description |
233
+ |---------|-------------|
234
+ | **Single File** | Everything in one `sutra.py` |
235
+ | **Multi-Format** | CSV, Excel, JSON, SQL, DataFrame |
236
+ | **No API Mode** | Use `.sql()` for free queries |
237
+ | **NLP Mode** | Use `.ask()` with OpenAI |
238
+ | **Auto Viz** | Set `viz=True` for charts |
239
+ | **Interactive** | `.interactive()` asks user |
240
+ | **Caching** | Saves API costs |
241
+ | **Export** | CSV, Excel, JSON |
242
+ | **Jupyter** | Perfect for notebooks |
243
+
244
+ ---
245
+
246
+ ## ๐Ÿ’ฐ Cost Saving
247
+
248
+ Use direct SQL to save API costs:
249
+
250
+ ```python
251
+ # FREE - No API call
252
+ result = sutra.sql("SELECT * FROM data WHERE amount > 1000")
253
+
254
+ # USES API - Costs ~$0.001 per query
255
+ result = sutra.ask("Show data where amount is greater than 1000")
256
+ ```
257
+
258
+ ---
259
+
260
+ ## ๐Ÿ“ Publishing to PyPI
261
+
262
+ See `PUBLISHING_GUIDE.md` for complete instructions.
263
+
264
+ Quick version:
265
+ ```bash
266
+ # Install tools
267
+ pip install build twine
268
+
269
+ # Build
270
+ python -m build
271
+
272
+ # Upload
273
+ python -m twine upload dist/*
274
+ ```
275
+
276
+ ---
277
+
278
+ ## ๐Ÿงช Testing
279
+
280
+ Run the test script:
281
+ ```bash
282
+ python test_package.py
283
+ ```
284
+
285
+ ---
286
+
287
+ ## ๐Ÿ“š Files Included
288
+
289
+ - `sutra/sutra.py` - Main single-file library
290
+ - `sutra/__init__.py` - Package initialization
291
+ - `SUTRA_Complete_Guide.ipynb` - Jupyter notebook tutorial
292
+ - `setup.py` - Package configuration
293
+ - `pyproject.toml` - Modern Python packaging
294
+ - `README.md` - This file
295
+ - `PUBLISHING_GUIDE.md` - How to publish
296
+ - `LICENSE` - MIT License
297
+
298
+ ---
299
+
300
+ ## ๐Ÿค Contributing
301
+
302
+ Contributions welcome! This is a single-file library, so it's easy to modify and extend.
303
+
304
+ ---
305
+
306
+ ## ๐Ÿ“„ License
307
+
308
+ MIT License - feel free to use in your projects!
309
+
310
+ ---
311
+
312
+ ## ๐ŸŽ“ Examples
313
+
314
+ ### Example 1: Quick Analysis
315
+ ```python
316
+ from sutra import SUTRA
317
+
318
+ sutra = SUTRA(api_key="sk-...")
319
+ sutra.upload("sales.csv")
320
+ result = sutra.ask("What region has highest sales?", viz=True)
321
+ print(result.data)
322
+ ```
323
+
324
+ ### Example 2: Multiple Queries
325
+ ```python
326
+ questions = [
327
+ "What are total sales?",
328
+ "Show top 5 products",
329
+ "Which region performs best?"
330
+ ]
331
+
332
+ for q in questions:
333
+ result = sutra.interactive(q) # Asks for viz each time
334
+ if result.success:
335
+ print(result.data)
336
+ ```
337
+
338
+ ### Example 3: Context Manager
339
+ ```python
340
+ with SUTRA(api_key="sk-...") as sutra:
341
+ sutra.upload(df)
342
+ result = sutra.ask("Show all", viz=True)
343
+ # Automatically closes
344
+ ```
345
+
346
+ ---
347
+
348
+ ## โ“ FAQ
349
+
350
+ **Q: Do I need an API key?**
351
+ A: Only for natural language queries (`.ask()`). Direct SQL (`.sql()`) works without API key.
352
+
353
+ **Q: What formats are supported?**
354
+ A: CSV, Excel (.xlsx, .xls), JSON, SQL files, and pandas DataFrames.
355
+
356
+ **Q: How do I visualize?**
357
+ A: Set `viz=True` in `.ask()` or `.sql()` methods, or use `.interactive()` to prompt user.
358
+
359
+ **Q: Can I use without Jupyter?**
360
+ A: Yes! Works in any Python environment - scripts, notebooks, REPL.
361
+
362
+ **Q: Is it a single file?**
363
+ A: Yes! The core is in `sutra/sutra.py` - one file with everything.
364
+
365
+ ---
366
+
367
+ ## ๐Ÿš€ Get Started Now!
368
+
369
+ ```bash
370
+ pip install sutra
371
+ ```
372
+
373
+ ```python
374
+ from sutra import SUTRA
375
+
376
+ sutra = SUTRA(api_key="your-key")
377
+ sutra.upload("data.csv")
378
+ result = sutra.ask("Show me insights", viz=True)
379
+ ```
380
+
381
+ **That's it! You're analyzing data with natural language!** ๐ŸŽ‰
382
+
383
+ ---
384
+
385
+ **Made with โค๏ธ by Aditya Batta**