persql 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.
- persql/__init__.py +195 -0
- persql/_async_database.py +851 -0
- persql/_client.py +322 -0
- persql/_database.py +942 -0
- persql/_errors.py +126 -0
- persql/_local.py +244 -0
- persql/_tools.py +932 -0
- persql/_transport.py +285 -0
- persql/_types.py +396 -0
- persql/py.typed +0 -0
- persql-0.1.0.dist-info/METADATA +215 -0
- persql-0.1.0.dist-info/RECORD +14 -0
- persql-0.1.0.dist-info/WHEEL +4 -0
- persql-0.1.0.dist-info/licenses/LICENSE +21 -0
persql/__init__.py
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"""PerSQL — SQLite databases on the edge for AI agents.
|
|
2
|
+
|
|
3
|
+
Quick start::
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from persql import PerSQL
|
|
7
|
+
|
|
8
|
+
persql = PerSQL(token=os.environ["PERSQL_TOKEN"])
|
|
9
|
+
db = persql.database("acme/orders")
|
|
10
|
+
result = db.query("SELECT id, email FROM customers WHERE id = ?", [42])
|
|
11
|
+
for row in result["data"]:
|
|
12
|
+
print(row["email"])
|
|
13
|
+
|
|
14
|
+
Async variant::
|
|
15
|
+
|
|
16
|
+
import asyncio
|
|
17
|
+
from persql import AsyncPerSQL
|
|
18
|
+
|
|
19
|
+
async def main():
|
|
20
|
+
async with AsyncPerSQL(token="...") as persql:
|
|
21
|
+
db = persql.database("acme/orders")
|
|
22
|
+
result = await db.query("SELECT 1 AS one")
|
|
23
|
+
print(result["data"])
|
|
24
|
+
|
|
25
|
+
asyncio.run(main())
|
|
26
|
+
|
|
27
|
+
Local mode (tests, no network)::
|
|
28
|
+
|
|
29
|
+
persql = PerSQL(local=":memory:")
|
|
30
|
+
db = persql.database("test/db")
|
|
31
|
+
db.query("CREATE TABLE t (id INTEGER)")
|
|
32
|
+
db.query("INSERT INTO t (id) VALUES (?)", [1])
|
|
33
|
+
print(db.query("SELECT * FROM t")["data"]) # [{"id": 1}]
|
|
34
|
+
|
|
35
|
+
Agent tools — one Anthropic + OpenAI + LangChain bundle covering the
|
|
36
|
+
whole database::
|
|
37
|
+
|
|
38
|
+
tools = db.as_tools()
|
|
39
|
+
# tools["anthropic"] — pass to anthropic.messages.create
|
|
40
|
+
# tools["openai"] — pass to openai.chat.completions.create
|
|
41
|
+
# tools["langchain"] — convert with DynamicStructuredTool
|
|
42
|
+
# tools["run"] — dispatcher to execute model-emitted calls
|
|
43
|
+
|
|
44
|
+
Errors::
|
|
45
|
+
|
|
46
|
+
from persql import ApprovalRequiredError, PerSQLError, RateLimitError
|
|
47
|
+
|
|
48
|
+
try:
|
|
49
|
+
db.query("UPDATE orders SET status='shipped'")
|
|
50
|
+
except ApprovalRequiredError as e:
|
|
51
|
+
print(f"Approval needed: {e.approval_url}")
|
|
52
|
+
except RateLimitError as e:
|
|
53
|
+
time.sleep(e.retry_after_seconds)
|
|
54
|
+
except PerSQLError as e:
|
|
55
|
+
# `.detail["kind"]` is set on /v1/query and /v1/batch SQL errors
|
|
56
|
+
print(e.status, e.args[0], getattr(e, "detail", None))
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
from __future__ import annotations
|
|
60
|
+
|
|
61
|
+
from ._async_database import (
|
|
62
|
+
AsyncPerSQLApprovals,
|
|
63
|
+
AsyncPerSQLBlob,
|
|
64
|
+
AsyncPerSQLBranches,
|
|
65
|
+
AsyncPerSQLDatabase,
|
|
66
|
+
AsyncPerSQLProposals,
|
|
67
|
+
AsyncPerSQLVectors,
|
|
68
|
+
)
|
|
69
|
+
from ._client import AsyncPerSQL, PerSQL
|
|
70
|
+
from ._database import (
|
|
71
|
+
PerSQLApprovals,
|
|
72
|
+
PerSQLBlob,
|
|
73
|
+
PerSQLBranches,
|
|
74
|
+
PerSQLDatabase,
|
|
75
|
+
PerSQLProposals,
|
|
76
|
+
PerSQLVectors,
|
|
77
|
+
)
|
|
78
|
+
from ._errors import (
|
|
79
|
+
ApprovalRequiredError,
|
|
80
|
+
ApprovalRuleHit,
|
|
81
|
+
PerSQLError,
|
|
82
|
+
RateLimitError,
|
|
83
|
+
SqlErrorDetail,
|
|
84
|
+
SqlErrorKind,
|
|
85
|
+
)
|
|
86
|
+
from ._tools import DatabaseToolBundle
|
|
87
|
+
from ._types import (
|
|
88
|
+
AnthropicTool,
|
|
89
|
+
BlobListItem,
|
|
90
|
+
BlobListResponse,
|
|
91
|
+
BlobPutResult,
|
|
92
|
+
BranchInfo,
|
|
93
|
+
BranchListPage,
|
|
94
|
+
BranchMergeMode,
|
|
95
|
+
BranchMergePlanStep,
|
|
96
|
+
BranchMergeResult,
|
|
97
|
+
BranchMergeSummary,
|
|
98
|
+
BranchMigration,
|
|
99
|
+
ClaimedBranch,
|
|
100
|
+
ColumnDescription,
|
|
101
|
+
DatabaseSchema,
|
|
102
|
+
DescribeBundle,
|
|
103
|
+
ForeignKeyDescription,
|
|
104
|
+
ForkedFrom,
|
|
105
|
+
HandoffClaim,
|
|
106
|
+
LangChainTool,
|
|
107
|
+
OpenAiTool,
|
|
108
|
+
OpenAiToolFunction,
|
|
109
|
+
PinnedHandoff,
|
|
110
|
+
ProposalPlan,
|
|
111
|
+
QueryLogEntry,
|
|
112
|
+
QueryLogPage,
|
|
113
|
+
QueryResult,
|
|
114
|
+
Role,
|
|
115
|
+
SchemaColumn,
|
|
116
|
+
SchemaDoctorFinding,
|
|
117
|
+
SchemaDoctorReport,
|
|
118
|
+
SchemaSearchHit,
|
|
119
|
+
SchemaSearchResponse,
|
|
120
|
+
SchemaTable,
|
|
121
|
+
Statement,
|
|
122
|
+
SubscribeChange,
|
|
123
|
+
SubscribeChangeKind,
|
|
124
|
+
TableDescription,
|
|
125
|
+
TableInfo,
|
|
126
|
+
VectorMatch,
|
|
127
|
+
VectorUpsertItem,
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
__version__ = "0.1.0"
|
|
131
|
+
|
|
132
|
+
__all__ = [
|
|
133
|
+
"AnthropicTool",
|
|
134
|
+
"ApprovalRequiredError",
|
|
135
|
+
"ApprovalRuleHit",
|
|
136
|
+
"AsyncPerSQL",
|
|
137
|
+
"AsyncPerSQLApprovals",
|
|
138
|
+
"AsyncPerSQLBlob",
|
|
139
|
+
"AsyncPerSQLBranches",
|
|
140
|
+
"AsyncPerSQLDatabase",
|
|
141
|
+
"AsyncPerSQLProposals",
|
|
142
|
+
"AsyncPerSQLVectors",
|
|
143
|
+
"BlobListItem",
|
|
144
|
+
"BlobListResponse",
|
|
145
|
+
"BlobPutResult",
|
|
146
|
+
"BranchInfo",
|
|
147
|
+
"BranchListPage",
|
|
148
|
+
"BranchMergeMode",
|
|
149
|
+
"BranchMergePlanStep",
|
|
150
|
+
"BranchMergeResult",
|
|
151
|
+
"BranchMergeSummary",
|
|
152
|
+
"BranchMigration",
|
|
153
|
+
"ClaimedBranch",
|
|
154
|
+
"ColumnDescription",
|
|
155
|
+
"DatabaseSchema",
|
|
156
|
+
"DatabaseToolBundle",
|
|
157
|
+
"DescribeBundle",
|
|
158
|
+
"ForeignKeyDescription",
|
|
159
|
+
"ForkedFrom",
|
|
160
|
+
"HandoffClaim",
|
|
161
|
+
"LangChainTool",
|
|
162
|
+
"OpenAiTool",
|
|
163
|
+
"OpenAiToolFunction",
|
|
164
|
+
"PerSQL",
|
|
165
|
+
"PerSQLApprovals",
|
|
166
|
+
"PerSQLBlob",
|
|
167
|
+
"PerSQLBranches",
|
|
168
|
+
"PerSQLDatabase",
|
|
169
|
+
"PerSQLError",
|
|
170
|
+
"PerSQLProposals",
|
|
171
|
+
"PerSQLVectors",
|
|
172
|
+
"PinnedHandoff",
|
|
173
|
+
"ProposalPlan",
|
|
174
|
+
"QueryLogEntry",
|
|
175
|
+
"QueryLogPage",
|
|
176
|
+
"QueryResult",
|
|
177
|
+
"RateLimitError",
|
|
178
|
+
"Role",
|
|
179
|
+
"SchemaColumn",
|
|
180
|
+
"SchemaDoctorFinding",
|
|
181
|
+
"SchemaDoctorReport",
|
|
182
|
+
"SchemaSearchHit",
|
|
183
|
+
"SchemaSearchResponse",
|
|
184
|
+
"SchemaTable",
|
|
185
|
+
"SqlErrorDetail",
|
|
186
|
+
"SqlErrorKind",
|
|
187
|
+
"Statement",
|
|
188
|
+
"SubscribeChange",
|
|
189
|
+
"SubscribeChangeKind",
|
|
190
|
+
"TableDescription",
|
|
191
|
+
"TableInfo",
|
|
192
|
+
"VectorMatch",
|
|
193
|
+
"VectorUpsertItem",
|
|
194
|
+
"__version__",
|
|
195
|
+
]
|