sqlspec 0.9.0__py3-none-any.whl → 0.9.1__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.
Potentially problematic release.
This version of sqlspec might be problematic. Click here for more details.
- sqlspec/adapters/adbc/driver.py +135 -3
- sqlspec/adapters/aiosqlite/driver.py +136 -3
- sqlspec/adapters/asyncmy/driver.py +136 -3
- sqlspec/adapters/asyncpg/driver.py +136 -2
- sqlspec/adapters/duckdb/driver.py +141 -11
- sqlspec/adapters/oracledb/driver.py +270 -4
- sqlspec/adapters/psqlpy/config.py +6 -14
- sqlspec/adapters/psqlpy/driver.py +149 -3
- sqlspec/adapters/psycopg/driver.py +306 -58
- sqlspec/adapters/sqlite/driver.py +136 -34
- sqlspec/base.py +413 -9
- sqlspec/extensions/litestar/plugin.py +2 -0
- {sqlspec-0.9.0.dist-info → sqlspec-0.9.1.dist-info}/METADATA +141 -2
- {sqlspec-0.9.0.dist-info → sqlspec-0.9.1.dist-info}/RECORD +17 -17
- {sqlspec-0.9.0.dist-info → sqlspec-0.9.1.dist-info}/WHEEL +0 -0
- {sqlspec-0.9.0.dist-info → sqlspec-0.9.1.dist-info}/licenses/LICENSE +0 -0
- {sqlspec-0.9.0.dist-info → sqlspec-0.9.1.dist-info}/licenses/NOTICE +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sqlspec
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.1
|
|
4
4
|
Summary: SQL Experiments in Python
|
|
5
5
|
Author-email: Cody Fincher <cody@litestar.dev>
|
|
6
6
|
Maintainer-email: Litestar Developers <hello@litestar.dev>
|
|
@@ -83,6 +83,145 @@ SQLSpec is an experimental Python library designed to streamline and modernize y
|
|
|
83
83
|
|
|
84
84
|
SQLSpec is a work in progress. While it offers a solid foundation for modern SQL interactions, it does not yet include every feature you might find in a mature ORM or database toolkit. The focus is on building a robust, flexible core that can be extended over time.
|
|
85
85
|
|
|
86
|
+
## Examples
|
|
87
|
+
|
|
88
|
+
We've talked about what SQLSpec is not, so let's look at what it can do.
|
|
89
|
+
|
|
90
|
+
These are just a few of the examples that demonstrate SQLSpec's flexibility and each of the bundled adapters offer the same config and driver interfaces.
|
|
91
|
+
|
|
92
|
+
### DuckDB LLM
|
|
93
|
+
|
|
94
|
+
This is a quick implementation using some of the built in Secret and Extension management features of SQLSpec's DuckDB integration.
|
|
95
|
+
|
|
96
|
+
It allows you to communicate with any compatible OpenAPI conversations endpoint (such as Ollama). This examples:
|
|
97
|
+
|
|
98
|
+
- auto installs the `open_prompt` DuckDB extensions
|
|
99
|
+
- automatically creates the correct `open_prompt` comptaible secret required to use the extension
|
|
100
|
+
|
|
101
|
+
```py
|
|
102
|
+
# /// script
|
|
103
|
+
# dependencies = [
|
|
104
|
+
# "sqlspec[duckdb,performance]",
|
|
105
|
+
# ]
|
|
106
|
+
# ///
|
|
107
|
+
import os
|
|
108
|
+
|
|
109
|
+
from sqlspec import SQLSpec
|
|
110
|
+
from sqlspec.adapters.duckdb import DuckDBConfig
|
|
111
|
+
from pydantic import BaseModel
|
|
112
|
+
|
|
113
|
+
class ChatMessage(BaseModel):
|
|
114
|
+
message: str
|
|
115
|
+
|
|
116
|
+
sql = SQLSpec()
|
|
117
|
+
etl_config = sql.add_config(
|
|
118
|
+
DuckDBConfig(
|
|
119
|
+
extensions=[{"name": "open_prompt"}],
|
|
120
|
+
secrets=[
|
|
121
|
+
{
|
|
122
|
+
"secret_type": "open_prompt",
|
|
123
|
+
"name": "open_prompt",
|
|
124
|
+
"value": {
|
|
125
|
+
"api_url": "http://127.0.0.1:11434/v1/chat/completions",
|
|
126
|
+
"model_name": "gemma3:1b",
|
|
127
|
+
"api_timeout": "120",
|
|
128
|
+
},
|
|
129
|
+
}
|
|
130
|
+
],
|
|
131
|
+
)
|
|
132
|
+
)
|
|
133
|
+
with sql.provide_session(etl_config) as session:
|
|
134
|
+
result = session.select_one("SELECT open_prompt(?)", data.message, schema_type=ChatMessage)
|
|
135
|
+
print(result) # result is a ChatMessage pydantic model
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### DuckDB Gemini Embeddings
|
|
139
|
+
|
|
140
|
+
In this example, we are again using DuckDB. However, we are going to use the built in to call the Google Gemini embeddings service directly from the database.
|
|
141
|
+
|
|
142
|
+
This example will
|
|
143
|
+
|
|
144
|
+
- auto installs the `http_client` and `vss` (vector similarity search) DuckDB extensions
|
|
145
|
+
- when a connection is created, it ensures that the `generate_embeddings` macro exists in the DuckDB database.
|
|
146
|
+
- Execute a simple query to call the Google API
|
|
147
|
+
|
|
148
|
+
```py
|
|
149
|
+
# /// script
|
|
150
|
+
# dependencies = [
|
|
151
|
+
# "sqlspec[duckdb,performance]",
|
|
152
|
+
# ]
|
|
153
|
+
# ///
|
|
154
|
+
import os
|
|
155
|
+
|
|
156
|
+
from sqlspec import SQLSpec
|
|
157
|
+
from sqlspec.adapters.duckdb import DuckDBConfig
|
|
158
|
+
|
|
159
|
+
EMBEDDING_MODEL = "gemini-embedding-exp-03-07"
|
|
160
|
+
GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY")
|
|
161
|
+
API_URL = (
|
|
162
|
+
f"https://generativelanguage.googleapis.com/v1beta/models/{EMBEDDING_MODEL}:embedContent?key=${GOOGLE_API_KEY}"
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
sql = SQLSpec()
|
|
166
|
+
etl_config = sql.add_config(
|
|
167
|
+
DuckDBConfig(
|
|
168
|
+
extensions=[{"name": "vss"}, {"name": "http_client"}],
|
|
169
|
+
on_connection_create=lambda connection: connection.execute(f"""
|
|
170
|
+
CREATE IF NOT EXISTS MACRO generate_embedding(q) AS (
|
|
171
|
+
WITH __request AS (
|
|
172
|
+
SELECT http_post(
|
|
173
|
+
'{API_URL}',
|
|
174
|
+
headers => MAP {{
|
|
175
|
+
'accept': 'application/json',
|
|
176
|
+
}},
|
|
177
|
+
params => MAP {{
|
|
178
|
+
'model': 'models/{EMBEDDING_MODEL}',
|
|
179
|
+
'parts': [{{ 'text': q }}],
|
|
180
|
+
'taskType': 'SEMANTIC_SIMILARITY'
|
|
181
|
+
}}
|
|
182
|
+
) AS response
|
|
183
|
+
)
|
|
184
|
+
SELECT *
|
|
185
|
+
FROM __request,
|
|
186
|
+
);
|
|
187
|
+
"""),
|
|
188
|
+
)
|
|
189
|
+
)
|
|
190
|
+
with sql.provide_session(etl_config) as session:
|
|
191
|
+
result = session.select_one("SELECT generate_embedding('example text')")
|
|
192
|
+
print(result) # result is a dictionary when `schema_type` is omitted.
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Basic Litestar Integration
|
|
196
|
+
|
|
197
|
+
In this example we are going to demonstrate how to create a basic configuration that integrates into Litestar.
|
|
198
|
+
|
|
199
|
+
```py
|
|
200
|
+
# /// script
|
|
201
|
+
# dependencies = [
|
|
202
|
+
# "sqlspec[aiosqlite]",
|
|
203
|
+
# "litestar[standard]",
|
|
204
|
+
# ]
|
|
205
|
+
# ///
|
|
206
|
+
|
|
207
|
+
from aiosqlite import Connection
|
|
208
|
+
from litestar import Litestar, get
|
|
209
|
+
|
|
210
|
+
from sqlspec.adapters.aiosqlite import AiosqliteConfig, AiosqliteDriver
|
|
211
|
+
from sqlspec.extensions.litestar import SQLSpec
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
@get("/")
|
|
215
|
+
async def simple_sqlite(db_session: AiosqliteDriver) -> dict[str, str]:
|
|
216
|
+
return await db_session.select_one("SELECT 'Hello, world!' AS greeting")
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
sqlspec = SQLSpec(config=DatabaseConfig(
|
|
220
|
+
config=[AiosqliteConfig(), commit_mode="autocommit")],
|
|
221
|
+
)
|
|
222
|
+
app = Litestar(route_handlers=[simple_sqlite], plugins=[sqlspec])
|
|
223
|
+
```
|
|
224
|
+
|
|
86
225
|
## Inspiration and Future Direction
|
|
87
226
|
|
|
88
227
|
SQLSpec originally drew inspiration from features found in the `aiosql` library. This is a great library for working with and executed SQL stored in files. It's unclear how much of an overlap there will be between the two libraries, but it's possible that some features will be contributed back to `aiosql` where appropriate.
|
|
@@ -121,7 +260,7 @@ This list is not final. If you have a driver you'd like to see added, please ope
|
|
|
121
260
|
- `sqlspec/`:
|
|
122
261
|
- `adapters/`: Contains all database drivers and associated configuration.
|
|
123
262
|
- `extensions/`:
|
|
124
|
-
- `litestar/`:
|
|
263
|
+
- `litestar/`: Litestar framework integration ✅
|
|
125
264
|
- `fastapi/`: Future home of `fastapi` integration.
|
|
126
265
|
- `flask/`: Future home of `flask` integration.
|
|
127
266
|
- `*/`: Future home of your favorite framework integration 🔌 ✨
|
|
@@ -2,7 +2,7 @@ sqlspec/__init__.py,sha256=dsOivB7SmZhOcWkZQT12L4LHC6fQhWBk2s_3j85KkgQ,316
|
|
|
2
2
|
sqlspec/__metadata__.py,sha256=hNP3wXvtk8fQVPKGjRLpZ9mP-gaPJqzrmgm3UqpDIXQ,460
|
|
3
3
|
sqlspec/_serialization.py,sha256=tSwWwFImlYviC6ARdXRz0Bp4QXbCdc8cKGgZr33OglY,2657
|
|
4
4
|
sqlspec/_typing.py,sha256=6ukndnNu_XWKf2OW-HP1x1L7YmqohMwjg2HF4Hq3xdU,7111
|
|
5
|
-
sqlspec/base.py,sha256
|
|
5
|
+
sqlspec/base.py,sha256=-FM0xIFZSKYv4pGC3dsbiKWv_8oMAKz-UZqhRJIdE2o,35007
|
|
6
6
|
sqlspec/exceptions.py,sha256=EyS7B9qyyTo78CdkC5iQDYFW9eXILDA6xiSS4ABr0Ws,4033
|
|
7
7
|
sqlspec/filters.py,sha256=Gqwt4VQ7e8ffphkuR-jBfqW4m0OWGGUPiYWyEQ0Xn7M,3620
|
|
8
8
|
sqlspec/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -11,51 +11,51 @@ sqlspec/typing.py,sha256=AI-72LFQcwwPoW5oEdEFkNHzxnWQv6I7lxcZRoZd88U,15428
|
|
|
11
11
|
sqlspec/adapters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
12
|
sqlspec/adapters/adbc/__init__.py,sha256=_mIoHMCXYWLCqGtnN8YEylhkNt3goTAvZgsT1dfEL6g,155
|
|
13
13
|
sqlspec/adapters/adbc/config.py,sha256=e2lrNsr8VN6R1ZBY16qusNj_W7npy7jp730NXCnhbBI,9866
|
|
14
|
-
sqlspec/adapters/adbc/driver.py,sha256=
|
|
14
|
+
sqlspec/adapters/adbc/driver.py,sha256=KpGxVhKf-6LoYNWfmng5VUR01GNjhHnOXBIkXznDwuE,19843
|
|
15
15
|
sqlspec/adapters/aiosqlite/__init__.py,sha256=TQME6tGSPswTkZBjW2oH39lbxpzSwwWG5SQfgFpSe00,185
|
|
16
16
|
sqlspec/adapters/aiosqlite/config.py,sha256=EjDJq9-Jn6MKnqlpL4ZwXYxaCKD0wE5GxrSYa2Ck1bA,4788
|
|
17
|
-
sqlspec/adapters/aiosqlite/driver.py,sha256=
|
|
17
|
+
sqlspec/adapters/aiosqlite/driver.py,sha256=yjsPhpJR-9c7AVzBDGi6GyGMzRW87Bls2F02c8WhCSA,15161
|
|
18
18
|
sqlspec/adapters/asyncmy/__init__.py,sha256=w0hjokFrsBgYS0EnIv8Dorb7jz8M3ZBZYKMUXCUYEQg,247
|
|
19
19
|
sqlspec/adapters/asyncmy/config.py,sha256=5ILV46FWjc9Cy46aMuhinpfc70b_708h9ubHj9HRCmE,9412
|
|
20
|
-
sqlspec/adapters/asyncmy/driver.py,sha256=
|
|
20
|
+
sqlspec/adapters/asyncmy/driver.py,sha256=Mjrb0ZWVwroCI-F9pNMDQsjFn2a1Kme2iyO9NJ5d0TM,12202
|
|
21
21
|
sqlspec/adapters/asyncpg/__init__.py,sha256=iR-vJYxImcw5hLaDgMqPLLRxW_vOYylEpemSg5G4dP4,261
|
|
22
22
|
sqlspec/adapters/asyncpg/config.py,sha256=DH6ZLkL4iHmRbW80VFQK1kzWIFRyGkFAZdtF3_f13AQ,9987
|
|
23
|
-
sqlspec/adapters/asyncpg/driver.py,sha256=
|
|
23
|
+
sqlspec/adapters/asyncpg/driver.py,sha256=7Zp-lxA3EqAgon5HdaKEtBl35S82WuMwSj-P1zh74HM,22333
|
|
24
24
|
sqlspec/adapters/duckdb/__init__.py,sha256=b_4QWZC0emTsbuBjcDZrxoEc83hGuBMx7Wwha3fFTAE,167
|
|
25
25
|
sqlspec/adapters/duckdb/config.py,sha256=GJTzKp1cEFhKSe94n5wOXvrT4Sz3Md8mKRxmCBnfvsM,15731
|
|
26
|
-
sqlspec/adapters/duckdb/driver.py,sha256=
|
|
26
|
+
sqlspec/adapters/duckdb/driver.py,sha256=NDgWlK6as96Vt_wCS7L8sI4wNjG0YwHfzg9q5OseYxU,13801
|
|
27
27
|
sqlspec/adapters/oracledb/__init__.py,sha256=g54_WLVzZhvD1sLC2uV0nfUs6WnYUJv2vqvvG34L7v0,398
|
|
28
|
-
sqlspec/adapters/oracledb/driver.py,sha256=
|
|
28
|
+
sqlspec/adapters/oracledb/driver.py,sha256=7lSALyAiT-4SXKx1e7m3Pzli8SwZvTLyif-Zacc--Bc,30439
|
|
29
29
|
sqlspec/adapters/oracledb/config/__init__.py,sha256=emx5jWXqw3ifoW-m_tNI7sTz_duq2vRkubc0J2QqEQ4,306
|
|
30
30
|
sqlspec/adapters/oracledb/config/_asyncio.py,sha256=hu4o5q_d1O7svR_XrylWcmMrvmBzOp0T1m_Ybrbbr_o,7293
|
|
31
31
|
sqlspec/adapters/oracledb/config/_common.py,sha256=UJZL2DQQZM3uOn1E1A_gnsB8nX3-yCDXGd66PDI29_s,5691
|
|
32
32
|
sqlspec/adapters/oracledb/config/_sync.py,sha256=wvmC8bX2FhSD3W-k4RUBXnMP6cvEThsO6-vA-q5flUY,7016
|
|
33
33
|
sqlspec/adapters/psqlpy/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
34
|
-
sqlspec/adapters/psqlpy/config.py,sha256=
|
|
35
|
-
sqlspec/adapters/psqlpy/driver.py,sha256=
|
|
34
|
+
sqlspec/adapters/psqlpy/config.py,sha256=f6A4jxOQdd8GHhmaIX4g8mbGXQFamRbgsKXecaZ1o60,10157
|
|
35
|
+
sqlspec/adapters/psqlpy/driver.py,sha256=ykbozMFMJ4k7v2q-9moAnRzY2H14Mv21s2_z_mC8oLE,16838
|
|
36
36
|
sqlspec/adapters/psycopg/__init__.py,sha256=_aCZRfDiC4lXM5UdkYEQEHZq-bqY1nyS_sioTM91Ul0,408
|
|
37
|
-
sqlspec/adapters/psycopg/driver.py,sha256=
|
|
37
|
+
sqlspec/adapters/psycopg/driver.py,sha256=edz1j_4v5ZGJidO5MzKqS4PNuXHJcV9fkoyyYh06bsA,28135
|
|
38
38
|
sqlspec/adapters/psycopg/config/__init__.py,sha256=TIFGht0TdHKC7NTJwaJPpG-6-BRRGzWfc2Bu756R-A4,310
|
|
39
39
|
sqlspec/adapters/psycopg/config/_async.py,sha256=6YpxNLxHwvI7r7ZBKKjWnd0xbEG1i4HLOOimiiDUr6w,6631
|
|
40
40
|
sqlspec/adapters/psycopg/config/_common.py,sha256=UqqvqPE9zlSO9G_Gh6fI190cHfCDG98S0GaznGAHpdU,2181
|
|
41
41
|
sqlspec/adapters/psycopg/config/_sync.py,sha256=QIybrGVkuu45GlAcYBzpcsRq7VW6EnHff4fcNATAgsw,6443
|
|
42
42
|
sqlspec/adapters/sqlite/__init__.py,sha256=cGsMyN4_ZWApbhtwmYG18PYEBRiO-NdOU6eecBxTwRQ,167
|
|
43
43
|
sqlspec/adapters/sqlite/config.py,sha256=m2TV-3jcjxIeMSCTsvvrTm50L6uE3007WVPluvqIX3Q,4447
|
|
44
|
-
sqlspec/adapters/sqlite/driver.py,sha256=
|
|
44
|
+
sqlspec/adapters/sqlite/driver.py,sha256=W-upeHQAiBRKqd-NBbOlgPuc1BLvSuEdt3BryWeVI1U,13749
|
|
45
45
|
sqlspec/extensions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
46
46
|
sqlspec/extensions/litestar/__init__.py,sha256=vJf0co-AUM75c7ZLil_TUCYilVNDtmVsdeVLbm9_xn8,512
|
|
47
47
|
sqlspec/extensions/litestar/_utils.py,sha256=UgwFxqLnjDw9S8G0H24DP2GsbMGas81W1lfhfTY68m8,1969
|
|
48
48
|
sqlspec/extensions/litestar/config.py,sha256=zq_mlwNubDhRAtAivi2d5S5ippJ1A5xhw19XC6yPC60,4443
|
|
49
49
|
sqlspec/extensions/litestar/handlers.py,sha256=6FNqIEWHUltnNuhcp8QNktK0j6-UB4isMpzoP7qCc3g,7932
|
|
50
|
-
sqlspec/extensions/litestar/plugin.py,sha256=
|
|
50
|
+
sqlspec/extensions/litestar/plugin.py,sha256=_W-wTrGsvNu9iMVXfhuYzJUxBZp-9oEp8GcJvm_oMhU,4942
|
|
51
51
|
sqlspec/utils/__init__.py,sha256=nVIUuMaHhhC1vXydoSBvnc-xTArqwWJaAtpjHhiM84Q,159
|
|
52
52
|
sqlspec/utils/deprecation.py,sha256=4pwGxoQYI3dAc3L1lh4tszZG6e2jp5m4e0ICk8SJx5M,3886
|
|
53
53
|
sqlspec/utils/fixtures.py,sha256=ni51rAuen6S1wuSi1kUwn6Qh25B-XrewPEsjV8G4gQ0,2029
|
|
54
54
|
sqlspec/utils/module_loader.py,sha256=tmMy9JcTTQETcwT8Wt8adCIuqr4zinQnPbCiBJ6JTSQ,2703
|
|
55
55
|
sqlspec/utils/sync_tools.py,sha256=xxHZ-5rnTrPEUNr7gxQUVvJd0NGJeO_MgisR8X7sI3c,10425
|
|
56
56
|
sqlspec/utils/text.py,sha256=Ya-fWBcfkQRhguNs7MNFIYtAUiArBo62w8sRPHavMWM,1476
|
|
57
|
-
sqlspec-0.9.
|
|
58
|
-
sqlspec-0.9.
|
|
59
|
-
sqlspec-0.9.
|
|
60
|
-
sqlspec-0.9.
|
|
61
|
-
sqlspec-0.9.
|
|
57
|
+
sqlspec-0.9.1.dist-info/METADATA,sha256=tk5LLeFdKAV99QguC9jnTD6BT6obRTSdfQLUGdmGanw,13935
|
|
58
|
+
sqlspec-0.9.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
59
|
+
sqlspec-0.9.1.dist-info/licenses/LICENSE,sha256=MdujfZ6l5HuLz4mElxlu049itenOR3gnhN1_Nd3nVcM,1078
|
|
60
|
+
sqlspec-0.9.1.dist-info/licenses/NOTICE,sha256=Lyir8ozXWov7CyYS4huVaOCNrtgL17P-bNV-5daLntQ,1634
|
|
61
|
+
sqlspec-0.9.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|