querychat 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1,165 @@
1
+ Metadata-Version: 2.4
2
+ Name: querychat
3
+ Version: 0.1.0
4
+ Summary: Chat with your data using natural language
5
+ Project-URL: Homepage, https://github.com/posit-dev/querychat
6
+ Project-URL: Issues, https://github.com/posit-dev/querychat/issues
7
+ Project-URL: Source, https://github.com/posit-dev/querychat/tree/main/python-package
8
+ Author-email: Posit <info@posit.co>
9
+ License: # MIT License
10
+
11
+ Copyright (c) 2025 Posit Software, PBC
12
+
13
+ Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ of this software and associated documentation files (the "Software"), to deal
15
+ in the Software without restriction, including without limitation the rights
16
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ copies of the Software, and to permit persons to whom the Software is
18
+ furnished to do so, subject to the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be included in all
21
+ copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ SOFTWARE.
30
+ License-File: LICENSE
31
+ Classifier: Programming Language :: Python
32
+ Classifier: Programming Language :: Python :: 3.8
33
+ Classifier: Programming Language :: Python :: 3.9
34
+ Classifier: Programming Language :: Python :: 3.10
35
+ Classifier: Programming Language :: Python :: 3.11
36
+ Classifier: Programming Language :: Python :: 3.12
37
+ Classifier: Programming Language :: Python :: 3.13
38
+ Requires-Python: >=3.8
39
+ Requires-Dist: chatlas
40
+ Requires-Dist: duckdb
41
+ Requires-Dist: htmltools
42
+ Requires-Dist: narwhals
43
+ Requires-Dist: pandas
44
+ Requires-Dist: shiny
45
+ Requires-Dist: shinywidgets
46
+ Description-Content-Type: text/markdown
47
+
48
+ # querychat for Python
49
+
50
+ Chat with your Shiny Python apps using natural language.
51
+
52
+ Imagine typing questions like these directly into your Shiny dashboard, and seeing the results in realtime:
53
+
54
+ * "Show only data from 2008 with highway MPG greater than 30."
55
+ * "What's the average city MPG for SUVs vs compact cars?"
56
+ * "Sort the data by highway fuel efficiency descending."
57
+
58
+ ## Installation
59
+
60
+ ```bash
61
+ pip install "querychat @ git+https://github.com/posit-dev/querychat#subdirectory=python-package"
62
+ ```
63
+
64
+ ## How to use
65
+
66
+ First, you'll need access to an LLM that supports tools/function calling. querychat uses [chatlas](https://github.com/posit-dev/chatlas) to interface with various providers.
67
+
68
+ Here's a minimal example (see [examples/app.py](examples/app.py) for an unabridged version):
69
+
70
+ ```python
71
+ from pathlib import Path
72
+
73
+ from seaborn import load_dataset
74
+ from shiny import App, render, ui
75
+
76
+ import querychat
77
+
78
+ titanic = load_dataset("titanic")
79
+
80
+ # 1. Configure querychat
81
+ querychat_config = querychat.init(titanic, "titanic")
82
+
83
+ # Create UI
84
+ app_ui = ui.page_sidebar(
85
+ # 2. Place the chat component in the sidebar
86
+ querychat.sidebar("chat"),
87
+ # Main panel with data viewer
88
+ ui.output_data_frame("data_table"),
89
+ title="querychat with Python",
90
+ fillable=True,
91
+ )
92
+
93
+
94
+ # Define server logic
95
+ def server(input, output, session):
96
+ # 3. Initialize querychat server with the config from step 1
97
+ chat = querychat.server("chat", querychat_config)
98
+
99
+ # 4. Display the filtered dataframe
100
+ @render.data_frame
101
+ def data_table():
102
+ # Access filtered data via chat.df() reactive
103
+ return chat["df"]()
104
+
105
+
106
+ # Create Shiny app
107
+ app = App(app_ui, server)
108
+ ```
109
+
110
+ ## Features
111
+
112
+ querychat uses LLMs to generate SQL queries from natural language, offering:
113
+
114
+ - **Reliability**: LLMs are excellent at writing SQL but bad at direct calculation
115
+ - **Transparency**: SQL is always displayed to the user
116
+ - **Reproducibility**: Generated SQL can be copied and reused elsewhere
117
+
118
+ ## Customization
119
+
120
+ ### Configure with your own data
121
+
122
+ ```python
123
+ querychat_config = querychat.init(
124
+ df=my_dataframe,
125
+ table_name="my_data", # Optional: defaults to "data"
126
+ greeting="Welcome! Ask me anything about the data.",
127
+ data_description="""
128
+ This dataset contains information about...
129
+ - column1: Description of column 1
130
+ - column2: Description of column 2
131
+ """,
132
+ extra_instructions="Please use British English spelling conventions."
133
+ )
134
+ ```
135
+
136
+ ### Use a different LLM provider
137
+
138
+ You can change the LLM provider or model by providing a callback function that takes a `system_prompt` argument and returns a `chatlas.Chat` object. (The parameter must be called `system_prompt` as it is passed by keyword.)
139
+
140
+ ```python
141
+ import chatlas
142
+
143
+ def my_chat_func(system_prompt: str) -> chatlas.Chat:
144
+ return chatlas.ChatAnthropic(
145
+ model="claude-3-5-sonnet-latest",
146
+ system_prompt=system_prompt
147
+ )
148
+
149
+ querychat_config = querychat.init(
150
+ df=my_dataframe,
151
+ create_chat_callback=my_chat_func
152
+ )
153
+ ```
154
+
155
+ ## How it works
156
+
157
+ querychat works by:
158
+
159
+ 1. Converting your pandas DataFrame to a DuckDB table
160
+ 2. Creating a system prompt with your data schema
161
+ 3. Setting up tools that let the LLM execute SQL queries
162
+ 4. Processing natural language to SQL queries
163
+ 5. Returning filtered data to your Shiny app
164
+
165
+ See the `examples/` directory for more complete examples.
@@ -0,0 +1,4 @@
1
+ querychat-0.1.0.dist-info/METADATA,sha256=jsh46OYtxbQbkLvCakocorDlJFFDqe3FqAGfd69mrvk,5549
2
+ querychat-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
3
+ querychat-0.1.0.dist-info/licenses/LICENSE,sha256=hZ84bObCqILwvQp6hoBRpXZvgYDJaoVEsODFJaSlVQQ,1078
4
+ querychat-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2025 Posit Software, PBC
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.