polygres-sdk 0.1.0__tar.gz → 0.2.1__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.
- {polygres_sdk-0.1.0 → polygres_sdk-0.2.1}/CONTRIBUTING.md +24 -3
- polygres_sdk-0.2.1/PKG-INFO +304 -0
- polygres_sdk-0.2.1/README.md +262 -0
- polygres_sdk-0.2.1/compatibility/0.1.0/README.md +10 -0
- polygres_sdk-0.2.1/compatibility/0.1.0/python-sdk-v1.methods.json +1366 -0
- polygres_sdk-0.2.1/docs/reference-v1.md +550 -0
- polygres_sdk-0.2.1/migrations/README.md +15 -0
- polygres_sdk-0.2.1/migrations/vector-configuration-creation.md +10 -0
- {polygres_sdk-0.1.0 → polygres_sdk-0.2.1}/pyproject.toml +25 -5
- {polygres_sdk-0.1.0 → polygres_sdk-0.2.1}/src/polygres/__init__.py +12 -0
- polygres_sdk-0.2.1/src/polygres/_api_version.py +19 -0
- polygres_sdk-0.2.1/src/polygres/_method_metadata.py +112 -0
- polygres_sdk-0.2.1/src/polygres/_vendor/__init__.py +1 -0
- polygres_sdk-0.2.1/src/polygres/_vendor/polygres_lib/__init__.py +1 -0
- polygres_sdk-0.2.1/src/polygres/_vendor/polygres_lib/api_versions.py +59 -0
- polygres_sdk-0.2.1/src/polygres/_vendor/polygres_lib/auth/__init__.py +41 -0
- polygres_sdk-0.2.1/src/polygres/_vendor/polygres_lib/auth/api_keys.py +151 -0
- polygres_sdk-0.2.1/src/polygres/_vendor/polygres_lib/auth/enums.py +581 -0
- polygres_sdk-0.2.1/src/polygres/_vendor/polygres_lib/auth/errors.py +895 -0
- polygres_sdk-0.2.1/src/polygres/_vendor/polygres_lib/auth/models.py +1013 -0
- polygres_sdk-0.2.1/src/polygres/_vendor/polygres_lib/auth/ports.py +300 -0
- polygres_sdk-0.2.1/src/polygres/_vendor/polygres_lib/auth/principals.py +177 -0
- polygres_sdk-0.2.1/src/polygres/_vendor/polygres_lib/auth/records.py +119 -0
- polygres_sdk-0.2.1/src/polygres/_vendor/polygres_lib/auth/types.py +267 -0
- polygres_sdk-0.2.1/src/polygres/_vendor/polygres_lib/context/__init__.py +87 -0
- polygres_sdk-0.2.1/src/polygres/_vendor/polygres_lib/context/enums.py +301 -0
- polygres_sdk-0.2.1/src/polygres/_vendor/polygres_lib/context/errors.py +266 -0
- polygres_sdk-0.2.1/src/polygres/_vendor/polygres_lib/context/models.py +1241 -0
- polygres_sdk-0.2.1/src/polygres/_vendor/polygres_lib/context/validation.py +454 -0
- polygres_sdk-0.2.1/src/polygres/_vendor/polygres_lib/core/__init__.py +1 -0
- polygres_sdk-0.2.1/src/polygres/_vendor/polygres_lib/core/models.py +21 -0
- polygres_sdk-0.2.1/src/polygres/_vendor/polygres_lib/core/types.py +95 -0
- polygres_sdk-0.2.1/src/polygres/_version.py +12 -0
- {polygres_sdk-0.1.0 → polygres_sdk-0.2.1}/src/polygres/client.py +476 -40
- polygres_sdk-0.2.1/src/polygres/context.py +1717 -0
- polygres_sdk-0.2.1/src/polygres/context_models.py +19 -0
- polygres_sdk-0.2.1/src/polygres/context_validation.py +105 -0
- polygres_sdk-0.2.1/src/polygres/context_wait.py +193 -0
- polygres_sdk-0.2.1/src/polygres/errors.py +121 -0
- {polygres_sdk-0.1.0 → polygres_sdk-0.2.1}/src/polygres/models.py +11 -5
- polygres_sdk-0.2.1/src/polygres/spec/__init__.py +39 -0
- polygres_sdk-0.2.1/src/polygres/spec/python-sdk-v1.methods.json +4461 -0
- polygres_sdk-0.2.1/src/polygres/spec/python-sdk-v1.methods.schema.json +286 -0
- polygres_sdk-0.2.1/src/polygres/spec/runtime-v1.openapi.json +13843 -0
- polygres_sdk-0.2.1/src/polygres/version_notices.py +258 -0
- polygres_sdk-0.2.1/tests/conftest.py +11 -0
- polygres_sdk-0.2.1/tests/fixtures/context/contract-fixtures.json +1688 -0
- {polygres_sdk-0.1.0 → polygres_sdk-0.2.1}/tests/test_client.py +325 -31
- polygres_sdk-0.2.1/tests/test_compatibility.py +121 -0
- polygres_sdk-0.2.1/tests/test_context.py +1116 -0
- polygres_sdk-0.2.1/tests/test_method_spec.py +106 -0
- polygres_sdk-0.2.1/tests/test_packaged_resources.py +19 -0
- polygres_sdk-0.2.1/tests/test_version.py +46 -0
- polygres_sdk-0.2.1/tests/test_version_notices.py +210 -0
- polygres_sdk-0.2.1/tools/check_sdk_compatibility.py +326 -0
- polygres_sdk-0.2.1/tools/generate_runtime_openapi_snapshot.py +215 -0
- polygres_sdk-0.2.1/tools/generate_sdk_method_spec.py +490 -0
- polygres_sdk-0.2.1/tools/run_context_live_test.sh +25 -0
- polygres_sdk-0.2.1/tools/runtime_operation_exclusions.json +164 -0
- polygres_sdk-0.2.1/tools/test_context_live.py +805 -0
- polygres_sdk-0.2.1/tools/verify_distribution.py +60 -0
- polygres_sdk-0.2.1/tools/verify_release_version.py +57 -0
- polygres_sdk-0.1.0/.github/workflows/ci.yml +0 -44
- polygres_sdk-0.1.0/.github/workflows/publish-python-sdk.yml +0 -99
- polygres_sdk-0.1.0/PKG-INFO +0 -400
- polygres_sdk-0.1.0/README.md +0 -362
- polygres_sdk-0.1.0/SECURITY.md +0 -22
- polygres_sdk-0.1.0/src/polygres/errors.py +0 -48
- {polygres_sdk-0.1.0 → polygres_sdk-0.2.1}/.gitignore +0 -0
- {polygres_sdk-0.1.0 → polygres_sdk-0.2.1}/LICENSE +0 -0
- {polygres_sdk-0.1.0 → polygres_sdk-0.2.1}/src/polygres/py.typed +0 -0
|
@@ -19,9 +19,30 @@ Run these before opening a pull request:
|
|
|
19
19
|
```bash
|
|
20
20
|
pytest
|
|
21
21
|
ruff check .
|
|
22
|
+
python tools/generate_runtime_openapi_snapshot.py --check
|
|
23
|
+
python tools/generate_sdk_method_spec.py --check
|
|
24
|
+
python tools/generate_sdk_method_spec.py --validate-only
|
|
25
|
+
python tools/check_sdk_compatibility.py \
|
|
26
|
+
--baseline compatibility/0.1.0/python-sdk-v1.methods.json
|
|
22
27
|
python -m build
|
|
28
|
+
python tools/verify_distribution.py dist/*.whl dist/*.tar.gz
|
|
23
29
|
```
|
|
24
30
|
|
|
31
|
+
The Runtime OpenAPI snapshot can be regenerated only from the Polygres
|
|
32
|
+
monorepo, where `services/api` is available. An SDK-only checkout can validate
|
|
33
|
+
the committed snapshot structure and canonical formatting, while the monorepo
|
|
34
|
+
sync gate performs the byte-for-byte application comparison.
|
|
35
|
+
|
|
36
|
+
Public methods stay hand-written and typed. Add non-wrapping binding metadata
|
|
37
|
+
and a description plus safe example for every new network method, then
|
|
38
|
+
regenerate the method JSON and reference page. Neither JSON artifact may be
|
|
39
|
+
used to route requests.
|
|
40
|
+
|
|
41
|
+
Use SemVer for the package. Before 1.0, breaking changes increment the minor
|
|
42
|
+
version and require a topic note in `migrations`; additive public changes also
|
|
43
|
+
increment the minor version. Internal fixes with unchanged public behavior use
|
|
44
|
+
a patch release.
|
|
45
|
+
|
|
25
46
|
## Publishing
|
|
26
47
|
|
|
27
48
|
Publishing uses GitHub Actions Trusted Publishing. Do not add PyPI API tokens
|
|
@@ -39,7 +60,7 @@ Release rehearsal happens first on TestPyPI:
|
|
|
39
60
|
/tmp/polygres-sdk-testpypi/bin/python -m pip install \
|
|
40
61
|
--index-url https://test.pypi.org/simple/ \
|
|
41
62
|
--extra-index-url https://pypi.org/simple/ \
|
|
42
|
-
polygres-sdk==0.1
|
|
63
|
+
polygres-sdk==0.2.1
|
|
43
64
|
/tmp/polygres-sdk-testpypi/bin/python - <<'PY'
|
|
44
65
|
import importlib.metadata
|
|
45
66
|
from polygres import Polygres
|
|
@@ -53,8 +74,8 @@ Publish to PyPI only after the same commit has passed TestPyPI validation. Push
|
|
|
53
74
|
a release tag from the public repository:
|
|
54
75
|
|
|
55
76
|
```bash
|
|
56
|
-
git tag polygres-sdk-v0.1
|
|
57
|
-
git push origin polygres-sdk-v0.1
|
|
77
|
+
git tag polygres-sdk-v0.2.1
|
|
78
|
+
git push origin polygres-sdk-v0.2.1
|
|
58
79
|
```
|
|
59
80
|
|
|
60
81
|
The `pypi` GitHub environment must be approved before the upload proceeds.
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: polygres-sdk
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: Python SDK for Polygres
|
|
5
|
+
Project-URL: Homepage, https://polygres.com
|
|
6
|
+
Project-URL: Documentation, https://docs.polygres.com/sdk
|
|
7
|
+
Project-URL: Repository, https://github.com/Evokoa/polygres-sdk
|
|
8
|
+
Project-URL: Changelog, https://github.com/Evokoa/polygres-sdk/blob/main/CHANGELOG.md
|
|
9
|
+
Project-URL: Issues, https://github.com/Evokoa/polygres-sdk/issues
|
|
10
|
+
Project-URL: Support, https://polygres.com
|
|
11
|
+
Author: Polygres
|
|
12
|
+
Maintainer-email: Polygres <support@polygres.com>
|
|
13
|
+
License: Apache-2.0
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Keywords: graph-search,hybrid-search,polygres,postgres,postgresql,retrieval,vector-search
|
|
16
|
+
Classifier: Development Status :: 3 - Alpha
|
|
17
|
+
Classifier: Intended Audience :: Developers
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
26
|
+
Classifier: Topic :: Database
|
|
27
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
28
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
29
|
+
Classifier: Typing :: Typed
|
|
30
|
+
Requires-Python: >=3.10
|
|
31
|
+
Requires-Dist: httpx>=0.28.1
|
|
32
|
+
Requires-Dist: pydantic<3,>=2.7
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: build>=1.2.2; extra == 'dev'
|
|
35
|
+
Requires-Dist: hatchling>=1.26.3; extra == 'dev'
|
|
36
|
+
Requires-Dist: jsonschema<5,>=4.23; extra == 'dev'
|
|
37
|
+
Requires-Dist: pytest>=8.3.4; extra == 'dev'
|
|
38
|
+
Requires-Dist: respx>=0.21.1; extra == 'dev'
|
|
39
|
+
Requires-Dist: ruff>=0.8.4; extra == 'dev'
|
|
40
|
+
Requires-Dist: tomli>=2.0.1; (python_version < '3.11') and extra == 'dev'
|
|
41
|
+
Description-Content-Type: text/markdown
|
|
42
|
+
|
|
43
|
+
# Polygres Python SDK
|
|
44
|
+
|
|
45
|
+
Build Python applications with Polygres graph, vector, text, and hybrid retrieval.
|
|
46
|
+
|
|
47
|
+
The SDK connects to one project's Runtime API using a Polygres API key. It does not open PostgreSQL connections or expose database passwords.
|
|
48
|
+
|
|
49
|
+
- [Documentation](https://docs.polygres.com)
|
|
50
|
+
- [Polygres](https://polygres.com)
|
|
51
|
+
- [Discord](https://discord.gg/GnHR8ezuwG)
|
|
52
|
+
|
|
53
|
+
## Install
|
|
54
|
+
|
|
55
|
+
The SDK requires Python 3.10 or newer.
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install polygres-sdk
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The SDK is a Python library and does not install the `polygres` terminal command. Install `polygres-cli` separately for project setup, imports, migrations, and retrieval configuration.
|
|
62
|
+
|
|
63
|
+
## Quick start
|
|
64
|
+
|
|
65
|
+
Create a Project API Key in **Settings** and copy the Runtime API URL from the project's **Connect** page. Store both values in your application's secret configuration.
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
import os
|
|
69
|
+
|
|
70
|
+
from polygres import Polygres
|
|
71
|
+
|
|
72
|
+
client = Polygres(
|
|
73
|
+
api_key=os.environ["POLYGRES_API_KEY"],
|
|
74
|
+
runtime_url=os.environ["POLYGRES_RUNTIME_URL"],
|
|
75
|
+
)
|
|
76
|
+
project = client.project()
|
|
77
|
+
|
|
78
|
+
readiness = project.readiness()
|
|
79
|
+
print(readiness.graph, readiness.vector, readiness.hybrid)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Use the Runtime API URL with the SDK. Do not use a direct or pooled PostgreSQL connection string.
|
|
83
|
+
|
|
84
|
+
## Choose a retrieval method
|
|
85
|
+
|
|
86
|
+
| Need | Method |
|
|
87
|
+
| --- | --- |
|
|
88
|
+
| Search by semantic similarity | `project.vector.search()` |
|
|
89
|
+
| Find rows similar to an existing row | `project.vector.similar_to()` |
|
|
90
|
+
| Search text with PostgreSQL full-text search | `project.text.tsvector()` |
|
|
91
|
+
| Tolerate misspellings in short text | `project.text.fuzzy()` |
|
|
92
|
+
| Traverse relationships | `project.graph.expand()` or `project.graph.related()` |
|
|
93
|
+
| Combine graph and vector relevance | `project.hybrid.*` |
|
|
94
|
+
|
|
95
|
+
The corresponding graph, vector, or text configuration must be ready before the application sends retrieval requests.
|
|
96
|
+
New vector setup uses `project.context.create_collection()` with a native
|
|
97
|
+
`pgcontext.vector` column. Existing `project.vector` retrieval methods remain available
|
|
98
|
+
for applications using previously registered vector configurations.
|
|
99
|
+
|
|
100
|
+
## Vector retrieval
|
|
101
|
+
|
|
102
|
+
Generate the query embedding with the same model and dimensions used by the saved vector configuration.
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
query_embedding = [0.1] * 768
|
|
106
|
+
|
|
107
|
+
page = project.vector.search(
|
|
108
|
+
query_embedding,
|
|
109
|
+
config="documents_embedding",
|
|
110
|
+
filters={"status": "published"},
|
|
111
|
+
min_similarity=0.75,
|
|
112
|
+
limit=10,
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
for result in page.results:
|
|
116
|
+
print(result.id, result.score, result.properties)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Find rows similar to an existing row without generating another embedding:
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
page = project.vector.similar_to(
|
|
123
|
+
row_id="doc_123",
|
|
124
|
+
config="documents_embedding",
|
|
125
|
+
limit=10,
|
|
126
|
+
)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Text retrieval
|
|
130
|
+
|
|
131
|
+
Full-text search:
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
page = project.text.tsvector(
|
|
135
|
+
"refund policy",
|
|
136
|
+
config="documents_body_tsv",
|
|
137
|
+
filters={"status": "published"},
|
|
138
|
+
limit=10,
|
|
139
|
+
)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Fuzzy text search:
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
page = project.text.fuzzy(
|
|
146
|
+
"acme corpration",
|
|
147
|
+
config="customer_name_fuzzy",
|
|
148
|
+
limit=10,
|
|
149
|
+
)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Graph retrieval
|
|
153
|
+
|
|
154
|
+
Graph methods start from real rows in graph-registered tables. Use an ID from trusted application data or a previous retrieval result.
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
start = {
|
|
158
|
+
"schema": "public",
|
|
159
|
+
"table": "documents",
|
|
160
|
+
"id": "doc_123",
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
page = project.graph.expand(
|
|
164
|
+
start,
|
|
165
|
+
max_depth=2,
|
|
166
|
+
direction="any",
|
|
167
|
+
limit=20,
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
for result in page.results:
|
|
171
|
+
print(result.node.id, result.depth, result.readable_path)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Other graph methods include:
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
neighbors = project.graph.neighborhood(start, radius=2, limit=20)
|
|
178
|
+
related = project.graph.related(start, limit=20)
|
|
179
|
+
|
|
180
|
+
target = {"schema": "public", "table": "documents", "id": "doc_456"}
|
|
181
|
+
paths = project.graph.path(start, target, max_depth=3)
|
|
182
|
+
connections = project.graph.connection([start, target], max_depth=3)
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
If a graph method returns `Node not found`, confirm that the row exists, its table is registered, and the graph was rebuilt after the latest relevant changes.
|
|
186
|
+
|
|
187
|
+
## Hybrid retrieval
|
|
188
|
+
|
|
189
|
+
Graph-first retrieval starts from a known row and adds vector relevance:
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
page = project.hybrid.graph_first(
|
|
193
|
+
start,
|
|
194
|
+
embedding=query_embedding,
|
|
195
|
+
config="documents_embedding",
|
|
196
|
+
max_depth=2,
|
|
197
|
+
limit=10,
|
|
198
|
+
)
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Vector-first retrieval finds semantic candidates before expanding graph context:
|
|
202
|
+
|
|
203
|
+
```python
|
|
204
|
+
page = project.hybrid.vector_first(
|
|
205
|
+
query_embedding,
|
|
206
|
+
config="documents_embedding",
|
|
207
|
+
vector_limit=20,
|
|
208
|
+
max_depth=1,
|
|
209
|
+
limit=10,
|
|
210
|
+
)
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Joint retrieval lets vector and graph rankings contribute independently:
|
|
214
|
+
|
|
215
|
+
```python
|
|
216
|
+
page = project.hybrid.joint(
|
|
217
|
+
query_embedding,
|
|
218
|
+
start,
|
|
219
|
+
config="documents_embedding",
|
|
220
|
+
vector_weight=0.7,
|
|
221
|
+
graph_weight=0.3,
|
|
222
|
+
max_depth=2,
|
|
223
|
+
limit=10,
|
|
224
|
+
)
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Pagination
|
|
228
|
+
|
|
229
|
+
Retrieval methods return a `Page` with `results`, `has_more`, and `next_cursor`.
|
|
230
|
+
|
|
231
|
+
```python
|
|
232
|
+
page = project.vector.search(
|
|
233
|
+
query_embedding,
|
|
234
|
+
config="documents_embedding",
|
|
235
|
+
limit=25,
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
for result in page.results:
|
|
239
|
+
print(result.id)
|
|
240
|
+
|
|
241
|
+
if page.has_more:
|
|
242
|
+
next_page = project.vector.search(
|
|
243
|
+
query_embedding,
|
|
244
|
+
config="documents_embedding",
|
|
245
|
+
limit=25,
|
|
246
|
+
cursor=page.next_cursor,
|
|
247
|
+
)
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Use `auto_paging_iter()` when you want the SDK to follow every page:
|
|
251
|
+
|
|
252
|
+
```python
|
|
253
|
+
for result in page.auto_paging_iter():
|
|
254
|
+
print(result.id, result.score)
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## Error handling
|
|
258
|
+
|
|
259
|
+
SDK exceptions include the HTTP status, stable error code, safe details, and request ID when available.
|
|
260
|
+
|
|
261
|
+
```python
|
|
262
|
+
from polygres import PolygresAPIError
|
|
263
|
+
|
|
264
|
+
try:
|
|
265
|
+
page = project.graph.expand(start, max_depth=2)
|
|
266
|
+
except PolygresAPIError as exc:
|
|
267
|
+
print(exc.status_code)
|
|
268
|
+
print(exc.code)
|
|
269
|
+
print(exc.request_id)
|
|
270
|
+
print(exc.details)
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
Keep the request ID when reporting a problem. Never log or send the Project API Key.
|
|
274
|
+
|
|
275
|
+
## Connection information
|
|
276
|
+
|
|
277
|
+
`connection_info()` returns project hosts and passwordless connection strings. It never returns the database password.
|
|
278
|
+
|
|
279
|
+
```python
|
|
280
|
+
connection = project.connection_info()
|
|
281
|
+
print(connection.direct_host)
|
|
282
|
+
print(connection.pooled_host)
|
|
283
|
+
print(connection.direct_url_without_password)
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
Use a PostgreSQL driver such as psycopg or SQLAlchemy when your application needs a database connection. The Polygres SDK is an HTTP retrieval client and does not bundle a PostgreSQL driver.
|
|
287
|
+
|
|
288
|
+
## Version and support
|
|
289
|
+
|
|
290
|
+
Package version: [`0.2.1`](https://github.com/Evokoa/polygres-sdk/releases/tag/polygres-sdk-v0.2.1).
|
|
291
|
+
|
|
292
|
+
When contacting support, include the installed SDK version and the request ID.
|
|
293
|
+
|
|
294
|
+
See the [SDK 0.2.1 release notes](https://github.com/Evokoa/polygres-sdk/releases/tag/polygres-sdk-v0.2.1) for release changes.
|
|
295
|
+
|
|
296
|
+
## Optional Agent Skill
|
|
297
|
+
|
|
298
|
+
The `polygres-sdk` Agent Skill helps compatible coding agents write and review Polygres application code.
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
npx skills add Evokoa/polygres-skills --skill polygres-sdk
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
See the [Agent Skills repository](https://github.com/Evokoa/polygres-skills) for Codex and Claude Code installation options.
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
# Polygres Python SDK
|
|
2
|
+
|
|
3
|
+
Build Python applications with Polygres graph, vector, text, and hybrid retrieval.
|
|
4
|
+
|
|
5
|
+
The SDK connects to one project's Runtime API using a Polygres API key. It does not open PostgreSQL connections or expose database passwords.
|
|
6
|
+
|
|
7
|
+
- [Documentation](https://docs.polygres.com)
|
|
8
|
+
- [Polygres](https://polygres.com)
|
|
9
|
+
- [Discord](https://discord.gg/GnHR8ezuwG)
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
The SDK requires Python 3.10 or newer.
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install polygres-sdk
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The SDK is a Python library and does not install the `polygres` terminal command. Install `polygres-cli` separately for project setup, imports, migrations, and retrieval configuration.
|
|
20
|
+
|
|
21
|
+
## Quick start
|
|
22
|
+
|
|
23
|
+
Create a Project API Key in **Settings** and copy the Runtime API URL from the project's **Connect** page. Store both values in your application's secret configuration.
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
import os
|
|
27
|
+
|
|
28
|
+
from polygres import Polygres
|
|
29
|
+
|
|
30
|
+
client = Polygres(
|
|
31
|
+
api_key=os.environ["POLYGRES_API_KEY"],
|
|
32
|
+
runtime_url=os.environ["POLYGRES_RUNTIME_URL"],
|
|
33
|
+
)
|
|
34
|
+
project = client.project()
|
|
35
|
+
|
|
36
|
+
readiness = project.readiness()
|
|
37
|
+
print(readiness.graph, readiness.vector, readiness.hybrid)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Use the Runtime API URL with the SDK. Do not use a direct or pooled PostgreSQL connection string.
|
|
41
|
+
|
|
42
|
+
## Choose a retrieval method
|
|
43
|
+
|
|
44
|
+
| Need | Method |
|
|
45
|
+
| --- | --- |
|
|
46
|
+
| Search by semantic similarity | `project.vector.search()` |
|
|
47
|
+
| Find rows similar to an existing row | `project.vector.similar_to()` |
|
|
48
|
+
| Search text with PostgreSQL full-text search | `project.text.tsvector()` |
|
|
49
|
+
| Tolerate misspellings in short text | `project.text.fuzzy()` |
|
|
50
|
+
| Traverse relationships | `project.graph.expand()` or `project.graph.related()` |
|
|
51
|
+
| Combine graph and vector relevance | `project.hybrid.*` |
|
|
52
|
+
|
|
53
|
+
The corresponding graph, vector, or text configuration must be ready before the application sends retrieval requests.
|
|
54
|
+
New vector setup uses `project.context.create_collection()` with a native
|
|
55
|
+
`pgcontext.vector` column. Existing `project.vector` retrieval methods remain available
|
|
56
|
+
for applications using previously registered vector configurations.
|
|
57
|
+
|
|
58
|
+
## Vector retrieval
|
|
59
|
+
|
|
60
|
+
Generate the query embedding with the same model and dimensions used by the saved vector configuration.
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
query_embedding = [0.1] * 768
|
|
64
|
+
|
|
65
|
+
page = project.vector.search(
|
|
66
|
+
query_embedding,
|
|
67
|
+
config="documents_embedding",
|
|
68
|
+
filters={"status": "published"},
|
|
69
|
+
min_similarity=0.75,
|
|
70
|
+
limit=10,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
for result in page.results:
|
|
74
|
+
print(result.id, result.score, result.properties)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Find rows similar to an existing row without generating another embedding:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
page = project.vector.similar_to(
|
|
81
|
+
row_id="doc_123",
|
|
82
|
+
config="documents_embedding",
|
|
83
|
+
limit=10,
|
|
84
|
+
)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Text retrieval
|
|
88
|
+
|
|
89
|
+
Full-text search:
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
page = project.text.tsvector(
|
|
93
|
+
"refund policy",
|
|
94
|
+
config="documents_body_tsv",
|
|
95
|
+
filters={"status": "published"},
|
|
96
|
+
limit=10,
|
|
97
|
+
)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Fuzzy text search:
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
page = project.text.fuzzy(
|
|
104
|
+
"acme corpration",
|
|
105
|
+
config="customer_name_fuzzy",
|
|
106
|
+
limit=10,
|
|
107
|
+
)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Graph retrieval
|
|
111
|
+
|
|
112
|
+
Graph methods start from real rows in graph-registered tables. Use an ID from trusted application data or a previous retrieval result.
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
start = {
|
|
116
|
+
"schema": "public",
|
|
117
|
+
"table": "documents",
|
|
118
|
+
"id": "doc_123",
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
page = project.graph.expand(
|
|
122
|
+
start,
|
|
123
|
+
max_depth=2,
|
|
124
|
+
direction="any",
|
|
125
|
+
limit=20,
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
for result in page.results:
|
|
129
|
+
print(result.node.id, result.depth, result.readable_path)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Other graph methods include:
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
neighbors = project.graph.neighborhood(start, radius=2, limit=20)
|
|
136
|
+
related = project.graph.related(start, limit=20)
|
|
137
|
+
|
|
138
|
+
target = {"schema": "public", "table": "documents", "id": "doc_456"}
|
|
139
|
+
paths = project.graph.path(start, target, max_depth=3)
|
|
140
|
+
connections = project.graph.connection([start, target], max_depth=3)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
If a graph method returns `Node not found`, confirm that the row exists, its table is registered, and the graph was rebuilt after the latest relevant changes.
|
|
144
|
+
|
|
145
|
+
## Hybrid retrieval
|
|
146
|
+
|
|
147
|
+
Graph-first retrieval starts from a known row and adds vector relevance:
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
page = project.hybrid.graph_first(
|
|
151
|
+
start,
|
|
152
|
+
embedding=query_embedding,
|
|
153
|
+
config="documents_embedding",
|
|
154
|
+
max_depth=2,
|
|
155
|
+
limit=10,
|
|
156
|
+
)
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Vector-first retrieval finds semantic candidates before expanding graph context:
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
page = project.hybrid.vector_first(
|
|
163
|
+
query_embedding,
|
|
164
|
+
config="documents_embedding",
|
|
165
|
+
vector_limit=20,
|
|
166
|
+
max_depth=1,
|
|
167
|
+
limit=10,
|
|
168
|
+
)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Joint retrieval lets vector and graph rankings contribute independently:
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
page = project.hybrid.joint(
|
|
175
|
+
query_embedding,
|
|
176
|
+
start,
|
|
177
|
+
config="documents_embedding",
|
|
178
|
+
vector_weight=0.7,
|
|
179
|
+
graph_weight=0.3,
|
|
180
|
+
max_depth=2,
|
|
181
|
+
limit=10,
|
|
182
|
+
)
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Pagination
|
|
186
|
+
|
|
187
|
+
Retrieval methods return a `Page` with `results`, `has_more`, and `next_cursor`.
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
page = project.vector.search(
|
|
191
|
+
query_embedding,
|
|
192
|
+
config="documents_embedding",
|
|
193
|
+
limit=25,
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
for result in page.results:
|
|
197
|
+
print(result.id)
|
|
198
|
+
|
|
199
|
+
if page.has_more:
|
|
200
|
+
next_page = project.vector.search(
|
|
201
|
+
query_embedding,
|
|
202
|
+
config="documents_embedding",
|
|
203
|
+
limit=25,
|
|
204
|
+
cursor=page.next_cursor,
|
|
205
|
+
)
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Use `auto_paging_iter()` when you want the SDK to follow every page:
|
|
209
|
+
|
|
210
|
+
```python
|
|
211
|
+
for result in page.auto_paging_iter():
|
|
212
|
+
print(result.id, result.score)
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## Error handling
|
|
216
|
+
|
|
217
|
+
SDK exceptions include the HTTP status, stable error code, safe details, and request ID when available.
|
|
218
|
+
|
|
219
|
+
```python
|
|
220
|
+
from polygres import PolygresAPIError
|
|
221
|
+
|
|
222
|
+
try:
|
|
223
|
+
page = project.graph.expand(start, max_depth=2)
|
|
224
|
+
except PolygresAPIError as exc:
|
|
225
|
+
print(exc.status_code)
|
|
226
|
+
print(exc.code)
|
|
227
|
+
print(exc.request_id)
|
|
228
|
+
print(exc.details)
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Keep the request ID when reporting a problem. Never log or send the Project API Key.
|
|
232
|
+
|
|
233
|
+
## Connection information
|
|
234
|
+
|
|
235
|
+
`connection_info()` returns project hosts and passwordless connection strings. It never returns the database password.
|
|
236
|
+
|
|
237
|
+
```python
|
|
238
|
+
connection = project.connection_info()
|
|
239
|
+
print(connection.direct_host)
|
|
240
|
+
print(connection.pooled_host)
|
|
241
|
+
print(connection.direct_url_without_password)
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Use a PostgreSQL driver such as psycopg or SQLAlchemy when your application needs a database connection. The Polygres SDK is an HTTP retrieval client and does not bundle a PostgreSQL driver.
|
|
245
|
+
|
|
246
|
+
## Version and support
|
|
247
|
+
|
|
248
|
+
Package version: [`0.2.1`](https://github.com/Evokoa/polygres-sdk/releases/tag/polygres-sdk-v0.2.1).
|
|
249
|
+
|
|
250
|
+
When contacting support, include the installed SDK version and the request ID.
|
|
251
|
+
|
|
252
|
+
See the [SDK 0.2.1 release notes](https://github.com/Evokoa/polygres-sdk/releases/tag/polygres-sdk-v0.2.1) for release changes.
|
|
253
|
+
|
|
254
|
+
## Optional Agent Skill
|
|
255
|
+
|
|
256
|
+
The `polygres-sdk` Agent Skill helps compatible coding agents write and review Polygres application code.
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
npx skills add Evokoa/polygres-skills --skill polygres-sdk
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
See the [Agent Skills repository](https://github.com/Evokoa/polygres-skills) for Codex and Claude Code installation options.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# SDK compatibility baseline 0.1.0
|
|
2
|
+
|
|
3
|
+
`python-sdk-v1.methods.json` is the explicit released 0.1.0 public network
|
|
4
|
+
surface used by CI and release checks for 0.2.0. It records the original
|
|
5
|
+
retrieval methods and marks Context operations as unavailable in that release.
|
|
6
|
+
The baseline uses the first formal stable operation identities because
|
|
7
|
+
generated FastAPI function names were not a published SDK contract in 0.1.0.
|
|
8
|
+
|
|
9
|
+
Release automation must name this file with `--baseline`; the compatibility
|
|
10
|
+
tool refuses to infer a baseline from an arbitrary local artifact.
|