synalinks-memory 0.0.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.
- synalinks_memory/__init__.py +34 -0
- synalinks_memory/client.py +268 -0
- synalinks_memory/exceptions.py +56 -0
- synalinks_memory/models.py +74 -0
- synalinks_memory/version.py +7 -0
- synalinks_memory-0.0.1.dist-info/METADATA +122 -0
- synalinks_memory-0.0.1.dist-info/RECORD +9 -0
- synalinks_memory-0.0.1.dist-info/WHEEL +4 -0
- synalinks_memory-0.0.1.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# License Apache 2.0: (c) 2026 Yoan Sallami (Synalinks Team)
|
|
2
|
+
|
|
3
|
+
"""Synalinks Memory Python SDK — public API surface and re-exports."""
|
|
4
|
+
|
|
5
|
+
from .version import __version__, version
|
|
6
|
+
from .client import SynalinksMemory
|
|
7
|
+
from .exceptions import (
|
|
8
|
+
AuthenticationError,
|
|
9
|
+
ForbiddenError,
|
|
10
|
+
NotFoundError,
|
|
11
|
+
RateLimitError,
|
|
12
|
+
SynalinksError,
|
|
13
|
+
ValidationError,
|
|
14
|
+
)
|
|
15
|
+
from .models import Column, ExecuteResult, PredicateInfo, PredicateList, SearchResult, UploadResult
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"__version__",
|
|
20
|
+
"version",
|
|
21
|
+
"AuthenticationError",
|
|
22
|
+
"Column",
|
|
23
|
+
"ExecuteResult",
|
|
24
|
+
"ForbiddenError",
|
|
25
|
+
"NotFoundError",
|
|
26
|
+
"PredicateInfo",
|
|
27
|
+
"PredicateList",
|
|
28
|
+
"RateLimitError",
|
|
29
|
+
"SearchResult",
|
|
30
|
+
"SynalinksError",
|
|
31
|
+
"SynalinksMemory",
|
|
32
|
+
"UploadResult",
|
|
33
|
+
"ValidationError",
|
|
34
|
+
]
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
# License Apache 2.0: (c) 2026 Yoan Sallami (Synalinks Team)
|
|
2
|
+
|
|
3
|
+
"""Synchronous HTTP client for the Synalinks Memory API."""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import logging
|
|
8
|
+
import os
|
|
9
|
+
import threading
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
import httpx
|
|
13
|
+
|
|
14
|
+
try:
|
|
15
|
+
import orjson as _json
|
|
16
|
+
|
|
17
|
+
def _loads(data: bytes | str) -> Any:
|
|
18
|
+
return _json.loads(data)
|
|
19
|
+
except ModuleNotFoundError:
|
|
20
|
+
import json as _json # type: ignore[no-redef]
|
|
21
|
+
|
|
22
|
+
def _loads(data: bytes | str) -> Any: # type: ignore[misc]
|
|
23
|
+
return _json.loads(data)
|
|
24
|
+
|
|
25
|
+
from .exceptions import (
|
|
26
|
+
AuthenticationError,
|
|
27
|
+
ForbiddenError,
|
|
28
|
+
NotFoundError,
|
|
29
|
+
RateLimitError,
|
|
30
|
+
SynalinksError,
|
|
31
|
+
ValidationError,
|
|
32
|
+
)
|
|
33
|
+
from .models import ExecuteResult, PredicateList, SearchResult, UploadResult
|
|
34
|
+
|
|
35
|
+
_ERROR_MAP: dict[int, type[SynalinksError]] = {
|
|
36
|
+
401: AuthenticationError,
|
|
37
|
+
403: ForbiddenError,
|
|
38
|
+
404: NotFoundError,
|
|
39
|
+
429: RateLimitError,
|
|
40
|
+
400: ValidationError,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
DEFAULT_BASE_URL = "https://app.synalinks.com/api"
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class SynalinksMemory:
|
|
48
|
+
"""Synchronous client for the Synalinks Memory API.
|
|
49
|
+
|
|
50
|
+
Usage::
|
|
51
|
+
|
|
52
|
+
client = SynalinksMemory() # reads SYNALINKS_API_KEY from env
|
|
53
|
+
predicates = client.list_predicates()
|
|
54
|
+
result = client.execute("MyTable", limit=10)
|
|
55
|
+
client.close()
|
|
56
|
+
|
|
57
|
+
Or as a context manager::
|
|
58
|
+
|
|
59
|
+
with SynalinksMemory() as client:
|
|
60
|
+
predicates = client.list_predicates()
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
def __init__(
|
|
64
|
+
self,
|
|
65
|
+
api_key: str | None = None,
|
|
66
|
+
base_url: str = DEFAULT_BASE_URL,
|
|
67
|
+
timeout: float = 30.0,
|
|
68
|
+
) -> None:
|
|
69
|
+
resolved_key = api_key or os.environ.get("SYNALINKS_API_KEY")
|
|
70
|
+
if not resolved_key:
|
|
71
|
+
raise AuthenticationError(
|
|
72
|
+
code="missing_api_key",
|
|
73
|
+
message=(
|
|
74
|
+
"No API key provided. Pass api_key= or set the "
|
|
75
|
+
"SYNALINKS_API_KEY environment variable."
|
|
76
|
+
),
|
|
77
|
+
)
|
|
78
|
+
self._client = httpx.Client(
|
|
79
|
+
base_url=base_url.rstrip("/"),
|
|
80
|
+
headers={"X-API-Key": resolved_key},
|
|
81
|
+
timeout=timeout,
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
# Fire a non-blocking request to wake up the backend (handles cold start)
|
|
85
|
+
self._warm_up()
|
|
86
|
+
|
|
87
|
+
# -- Warm-up ---------------------------------------------------------------
|
|
88
|
+
|
|
89
|
+
def _warm_up(self) -> None:
|
|
90
|
+
"""Send a background health check to wake up the backend container."""
|
|
91
|
+
|
|
92
|
+
def _ping() -> None:
|
|
93
|
+
try:
|
|
94
|
+
self._client.get("/v1/health")
|
|
95
|
+
except Exception:
|
|
96
|
+
logging.getLogger(__name__).debug(
|
|
97
|
+
"Warm-up request failed (backend may be starting)"
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
thread = threading.Thread(target=_ping, daemon=True)
|
|
101
|
+
thread.start()
|
|
102
|
+
|
|
103
|
+
# -- Context manager -------------------------------------------------------
|
|
104
|
+
|
|
105
|
+
def __enter__(self) -> SynalinksMemory:
|
|
106
|
+
return self
|
|
107
|
+
|
|
108
|
+
def __exit__(self, *args: Any) -> None:
|
|
109
|
+
self.close()
|
|
110
|
+
|
|
111
|
+
def close(self) -> None:
|
|
112
|
+
"""Close the underlying HTTP client."""
|
|
113
|
+
self._client.close()
|
|
114
|
+
|
|
115
|
+
# -- Public API ------------------------------------------------------------
|
|
116
|
+
|
|
117
|
+
def list(self) -> PredicateList:
|
|
118
|
+
"""List all available predicates (tables, concepts, rules)."""
|
|
119
|
+
resp = self._client.get("/v1/predicates")
|
|
120
|
+
self._handle_response(resp)
|
|
121
|
+
return PredicateList.model_validate(_loads(resp.content))
|
|
122
|
+
|
|
123
|
+
def execute(
|
|
124
|
+
self,
|
|
125
|
+
predicate: str,
|
|
126
|
+
*,
|
|
127
|
+
limit: int = 100,
|
|
128
|
+
offset: int = 0,
|
|
129
|
+
format: str | None = None,
|
|
130
|
+
output: str | None = None,
|
|
131
|
+
) -> ExecuteResult | bytes | int:
|
|
132
|
+
"""Execute a predicate and return rows.
|
|
133
|
+
|
|
134
|
+
Args:
|
|
135
|
+
predicate: The predicate name to execute.
|
|
136
|
+
limit: Max rows to return (1–1000).
|
|
137
|
+
offset: Row offset for pagination.
|
|
138
|
+
format: If set to ``json``, ``csv``, or ``parquet``, returns raw
|
|
139
|
+
file bytes instead of an ``ExecuteResult``.
|
|
140
|
+
output: Write the file bytes to this path (only used with *format*).
|
|
141
|
+
When provided, the response is streamed directly to disk to
|
|
142
|
+
avoid buffering large exports in memory, and the return value
|
|
143
|
+
is the number of bytes written.
|
|
144
|
+
|
|
145
|
+
Returns:
|
|
146
|
+
``ExecuteResult`` when *format* is None; the number of bytes
|
|
147
|
+
written (``int``) when both *format* and *output* are set;
|
|
148
|
+
raw ``bytes`` when only *format* is set.
|
|
149
|
+
"""
|
|
150
|
+
body: dict[str, Any] = {"limit": limit, "offset": offset}
|
|
151
|
+
if format is not None:
|
|
152
|
+
body["format"] = format
|
|
153
|
+
|
|
154
|
+
if format is not None and output:
|
|
155
|
+
# Stream directly to disk — avoids buffering the entire file
|
|
156
|
+
with self._client.stream(
|
|
157
|
+
"POST",
|
|
158
|
+
f"/v1/predicates/{predicate}/execute",
|
|
159
|
+
json=body,
|
|
160
|
+
) as stream:
|
|
161
|
+
self._handle_response(stream)
|
|
162
|
+
written = 0
|
|
163
|
+
with open(output, "wb") as f:
|
|
164
|
+
for chunk in stream.iter_bytes(chunk_size=65_536):
|
|
165
|
+
f.write(chunk)
|
|
166
|
+
written += len(chunk)
|
|
167
|
+
return written
|
|
168
|
+
|
|
169
|
+
resp = self._client.post(
|
|
170
|
+
f"/v1/predicates/{predicate}/execute",
|
|
171
|
+
json=body,
|
|
172
|
+
)
|
|
173
|
+
self._handle_response(resp)
|
|
174
|
+
|
|
175
|
+
if format is not None:
|
|
176
|
+
return resp.content
|
|
177
|
+
|
|
178
|
+
return ExecuteResult.model_validate(_loads(resp.content))
|
|
179
|
+
|
|
180
|
+
def search(
|
|
181
|
+
self, predicate: str, keywords: str, *, limit: int = 100, offset: int = 0
|
|
182
|
+
) -> SearchResult:
|
|
183
|
+
"""Search a predicate by keywords."""
|
|
184
|
+
resp = self._client.post(
|
|
185
|
+
f"/v1/predicates/{predicate}/search",
|
|
186
|
+
json={"keywords": keywords, "limit": limit, "offset": offset},
|
|
187
|
+
)
|
|
188
|
+
self._handle_response(resp)
|
|
189
|
+
return SearchResult.model_validate(_loads(resp.content))
|
|
190
|
+
|
|
191
|
+
def upload(
|
|
192
|
+
self,
|
|
193
|
+
file_path: str,
|
|
194
|
+
*,
|
|
195
|
+
name: str | None = None,
|
|
196
|
+
description: str | None = None,
|
|
197
|
+
overwrite: bool = False,
|
|
198
|
+
) -> UploadResult:
|
|
199
|
+
"""Upload a CSV or Parquet file as a new table.
|
|
200
|
+
|
|
201
|
+
Args:
|
|
202
|
+
file_path: Local path to a .csv or .parquet file.
|
|
203
|
+
name: Optional predicate name (CamelCase). Derived from filename if omitted.
|
|
204
|
+
description: Optional table description.
|
|
205
|
+
overwrite: If True, replace an existing table with the same name.
|
|
206
|
+
|
|
207
|
+
Returns:
|
|
208
|
+
UploadResult with predicate name, columns, and row count.
|
|
209
|
+
"""
|
|
210
|
+
import os as _os
|
|
211
|
+
|
|
212
|
+
with open(file_path, "rb") as f:
|
|
213
|
+
files = {"file": (_os.path.basename(file_path), f)}
|
|
214
|
+
data: dict[str, str] = {}
|
|
215
|
+
if name is not None:
|
|
216
|
+
data["name"] = name
|
|
217
|
+
if description is not None:
|
|
218
|
+
data["description"] = description
|
|
219
|
+
if overwrite:
|
|
220
|
+
data["overwrite"] = "true"
|
|
221
|
+
|
|
222
|
+
resp = self._client.post("/v1/tables/upload", files=files, data=data)
|
|
223
|
+
|
|
224
|
+
self._handle_response(resp)
|
|
225
|
+
return UploadResult.model_validate(_loads(resp.content))
|
|
226
|
+
|
|
227
|
+
def ask(self, question: str) -> str:
|
|
228
|
+
"""Ask the Synalinks agent a question and get a single-turn answer.
|
|
229
|
+
|
|
230
|
+
Args:
|
|
231
|
+
question: The question to ask.
|
|
232
|
+
|
|
233
|
+
Returns:
|
|
234
|
+
The agent's answer as a string.
|
|
235
|
+
"""
|
|
236
|
+
resp = self._client.post("/v1/ask", json={"question": question})
|
|
237
|
+
self._handle_response(resp)
|
|
238
|
+
return _loads(resp.content)["answer"]
|
|
239
|
+
|
|
240
|
+
# -- Internals -------------------------------------------------------------
|
|
241
|
+
|
|
242
|
+
@staticmethod
|
|
243
|
+
def _handle_response(resp: httpx.Response) -> None:
|
|
244
|
+
"""Raise a typed exception for non-2xx responses."""
|
|
245
|
+
if resp.is_success:
|
|
246
|
+
return
|
|
247
|
+
|
|
248
|
+
# Try to parse the structured error envelope
|
|
249
|
+
code = "unknown"
|
|
250
|
+
message = resp.text
|
|
251
|
+
try:
|
|
252
|
+
body = _loads(resp.content)
|
|
253
|
+
error = body.get("error", {})
|
|
254
|
+
code = error.get("code", code)
|
|
255
|
+
message = error.get("message", message)
|
|
256
|
+
except Exception:
|
|
257
|
+
pass
|
|
258
|
+
|
|
259
|
+
# Handle 429 specially for retry_after
|
|
260
|
+
if resp.status_code == 429:
|
|
261
|
+
retry_after_raw = resp.headers.get("Retry-After")
|
|
262
|
+
retry_after = float(retry_after_raw) if retry_after_raw else None
|
|
263
|
+
raise RateLimitError(code=code, message=message, retry_after=retry_after)
|
|
264
|
+
|
|
265
|
+
exc_cls = _ERROR_MAP.get(resp.status_code, SynalinksError)
|
|
266
|
+
if exc_cls is SynalinksError:
|
|
267
|
+
raise SynalinksError(resp.status_code, code, message)
|
|
268
|
+
raise exc_cls(code=code, message=message)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# License Apache 2.0: (c) 2026 Yoan Sallami (Synalinks Team)
|
|
2
|
+
|
|
3
|
+
"""Typed exception hierarchy for Synalinks API errors."""
|
|
4
|
+
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SynalinksError(Exception):
|
|
9
|
+
"""Base exception for all Synalinks API errors."""
|
|
10
|
+
|
|
11
|
+
def __init__(self, status_code: int, code: str, message: str) -> None:
|
|
12
|
+
self.status_code = status_code
|
|
13
|
+
self.code = code
|
|
14
|
+
self.message = message
|
|
15
|
+
super().__init__(f"[{status_code}] {code}: {message}")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class AuthenticationError(SynalinksError):
|
|
19
|
+
"""Raised on 401 Unauthorized."""
|
|
20
|
+
|
|
21
|
+
def __init__(self, code: str = "unauthorized", message: str = "Invalid API key") -> None:
|
|
22
|
+
super().__init__(401, code, message)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class ForbiddenError(SynalinksError):
|
|
26
|
+
"""Raised on 403 Forbidden."""
|
|
27
|
+
|
|
28
|
+
def __init__(self, code: str = "forbidden", message: str = "Access denied") -> None:
|
|
29
|
+
super().__init__(403, code, message)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class NotFoundError(SynalinksError):
|
|
33
|
+
"""Raised on 404 Not Found."""
|
|
34
|
+
|
|
35
|
+
def __init__(self, code: str = "not_found", message: str = "Resource not found") -> None:
|
|
36
|
+
super().__init__(404, code, message)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class RateLimitError(SynalinksError):
|
|
40
|
+
"""Raised on 429 Too Many Requests."""
|
|
41
|
+
|
|
42
|
+
def __init__(
|
|
43
|
+
self,
|
|
44
|
+
code: str = "rate_limit_exceeded",
|
|
45
|
+
message: str = "Rate limit exceeded",
|
|
46
|
+
retry_after: Optional[float] = None,
|
|
47
|
+
) -> None:
|
|
48
|
+
self.retry_after = retry_after
|
|
49
|
+
super().__init__(429, code, message)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class ValidationError(SynalinksError):
|
|
53
|
+
"""Raised on 400 Bad Request."""
|
|
54
|
+
|
|
55
|
+
def __init__(self, code: str = "validation_error", message: str = "Bad request") -> None:
|
|
56
|
+
super().__init__(400, code, message)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# License Apache 2.0: (c) 2026 Yoan Sallami (Synalinks Team)
|
|
2
|
+
|
|
3
|
+
"""Pydantic models for API request and response payloads."""
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from pydantic import BaseModel, ConfigDict
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class PredicateInfo(BaseModel):
|
|
11
|
+
"""A single predicate (table, concept, or rule)."""
|
|
12
|
+
|
|
13
|
+
name: str
|
|
14
|
+
description: str = ""
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class PredicateList(BaseModel):
|
|
18
|
+
"""Response from GET /v1/predicates."""
|
|
19
|
+
|
|
20
|
+
tables: list[PredicateInfo] = []
|
|
21
|
+
concepts: list[PredicateInfo] = []
|
|
22
|
+
rules: list[PredicateInfo] = []
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class Column(BaseModel):
|
|
26
|
+
"""Column metadata returned alongside query results."""
|
|
27
|
+
|
|
28
|
+
name: str
|
|
29
|
+
json_schema: dict[str, Any] = {}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class ExecuteResult(BaseModel):
|
|
33
|
+
"""Response from POST /v1/predicates/{name}/execute.
|
|
34
|
+
|
|
35
|
+
``rows`` uses arbitrary_types_allowed so Pydantic passes the
|
|
36
|
+
already-deserialized list[dict] through without re-validating
|
|
37
|
+
every cell — critical for large result sets.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
41
|
+
|
|
42
|
+
predicate: str
|
|
43
|
+
columns: list[Column]
|
|
44
|
+
rows: Any # list[dict[str, Any]] — skip per-row validation
|
|
45
|
+
row_count: int
|
|
46
|
+
total_rows: int
|
|
47
|
+
offset: int
|
|
48
|
+
limit: int
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class SearchResult(BaseModel):
|
|
52
|
+
"""Response from POST /v1/predicates/{name}/search.
|
|
53
|
+
|
|
54
|
+
See ``ExecuteResult`` for the ``rows`` optimisation rationale.
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
58
|
+
|
|
59
|
+
predicate: str
|
|
60
|
+
keywords: str
|
|
61
|
+
columns: list[Column]
|
|
62
|
+
rows: Any # list[dict[str, Any]] — skip per-row validation
|
|
63
|
+
row_count: int
|
|
64
|
+
total_rows: int
|
|
65
|
+
offset: int
|
|
66
|
+
limit: int
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class UploadResult(BaseModel):
|
|
70
|
+
"""Response from POST /v1/tables/upload."""
|
|
71
|
+
|
|
72
|
+
predicate: str
|
|
73
|
+
columns: list[Column]
|
|
74
|
+
row_count: int
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: synalinks-memory
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Python SDK for the Synalinks Memory API
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Requires-Dist: httpx>=0.27
|
|
9
|
+
Requires-Dist: pydantic>=2.0
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# Synalinks Memory Python SDK
|
|
13
|
+
|
|
14
|
+
**Synalinks Memory** is the knowledge and context layer for AI agents. It lets your agents always have the right context at the right time. Unlike retrieval systems that compound LLM errors at every step, Synalinks uses **logical rules** to derive knowledge from your raw data. Every claim can be traced back to evidence, from raw data to insight, no more lies or hallucinations.
|
|
15
|
+
|
|
16
|
+
This SDK provides a Python client to interact with the Synalinks Memory API, so your agents can store, query, and reason over their knowledge base programmatically.
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install synalinks-memory
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Or with [uv](https://docs.astral.sh/uv/):
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
uv add synalinks-memory
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
Set your API key as an environment variable:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
export SYNALINKS_API_KEY="synalinks_..."
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Then query your data:
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from synalinks_memory import SynalinksMemory
|
|
42
|
+
|
|
43
|
+
with SynalinksMemory() as client:
|
|
44
|
+
# List all available tables, concepts, and rules
|
|
45
|
+
predicates = client.list()
|
|
46
|
+
for table in predicates.tables:
|
|
47
|
+
print(f"{table.name}: {table.description}")
|
|
48
|
+
|
|
49
|
+
# Fetch rows from a table
|
|
50
|
+
result = client.execute("Users", limit=10)
|
|
51
|
+
for row in result.rows:
|
|
52
|
+
print(row)
|
|
53
|
+
|
|
54
|
+
# Search with keywords (fuzzy matching)
|
|
55
|
+
result = client.search("Users", "alice")
|
|
56
|
+
for row in result.rows:
|
|
57
|
+
print(row)
|
|
58
|
+
|
|
59
|
+
# Upload a CSV or Parquet file
|
|
60
|
+
upload = client.upload("data/sales.csv", name="Sales", description="Monthly sales data")
|
|
61
|
+
print(f"Uploaded {upload.predicate} ({upload.row_count} rows)")
|
|
62
|
+
|
|
63
|
+
# Export data as a file (CSV, Parquet, or JSON)
|
|
64
|
+
client.execute("Users", format="csv", output="users.csv")
|
|
65
|
+
client.execute("Users", format="parquet", output="users.parquet")
|
|
66
|
+
|
|
67
|
+
# Ask the agent a question
|
|
68
|
+
answer = client.ask("What were the top 5 products by revenue last month?")
|
|
69
|
+
print(answer)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
You can also pass the key directly:
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
client = SynalinksMemory(api_key="synalinks_...")
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Error Handling
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
from synalinks_memory import (
|
|
82
|
+
SynalinksMemory,
|
|
83
|
+
AuthenticationError,
|
|
84
|
+
NotFoundError,
|
|
85
|
+
RateLimitError,
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
with SynalinksMemory() as client:
|
|
89
|
+
try:
|
|
90
|
+
result = client.execute("MyTable")
|
|
91
|
+
except AuthenticationError:
|
|
92
|
+
print("Invalid API key")
|
|
93
|
+
except NotFoundError as e:
|
|
94
|
+
print(f"Not found: {e.message}")
|
|
95
|
+
except RateLimitError as e:
|
|
96
|
+
print(f"Rate limited, retry after {e.retry_after}s")
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## API Reference
|
|
100
|
+
|
|
101
|
+
### `SynalinksMemory(api_key=None, base_url=None, timeout=30.0)`
|
|
102
|
+
|
|
103
|
+
| Parameter | Description |
|
|
104
|
+
|-----------|-------------|
|
|
105
|
+
| `api_key` | Your API key. If omitted, reads from `SYNALINKS_API_KEY` env var. |
|
|
106
|
+
| `base_url` | Override the API endpoint (defaults to `https://app.synalinks.com/api`). |
|
|
107
|
+
| `timeout` | Request timeout in seconds. |
|
|
108
|
+
|
|
109
|
+
### Methods
|
|
110
|
+
|
|
111
|
+
| Method | Description |
|
|
112
|
+
|--------|-------------|
|
|
113
|
+
| `list()` | List all tables, concepts, and rules |
|
|
114
|
+
| `execute(predicate, *, limit=100, offset=0, format=None, output=None)` | Fetch rows (or export as json/csv/parquet file when *format* is set) |
|
|
115
|
+
| `search(predicate, keywords, *, limit=100, offset=0)` | Search rows by keywords (fuzzy matching) |
|
|
116
|
+
| `upload(file_path, *, name=None, description=None, overwrite=False)` | Upload a CSV or Parquet file as a new table |
|
|
117
|
+
| `ask(question)` | Ask the agent a question, returns the answer string |
|
|
118
|
+
| `close()` | Close the HTTP client (not needed with `with` statement) |
|
|
119
|
+
|
|
120
|
+
## License
|
|
121
|
+
|
|
122
|
+
Apache 2.0
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
synalinks_memory/__init__.py,sha256=B75YH8BRyxG7s5HfFouCSvpgqQi5SkNv094IKPquwV8,794
|
|
2
|
+
synalinks_memory/client.py,sha256=jwcbm5jsmHSt7SJesrmRItYz97vCtq_-Z-1i7yZuZZo,8725
|
|
3
|
+
synalinks_memory/exceptions.py,sha256=MQrE8oLvq5cGNgIpQ0AjKCu9p0bBMzHAB-QutAFUX7A,1687
|
|
4
|
+
synalinks_memory/models.py,sha256=6OD5a2fdaoqfDjYd1wUeIEWsR0_iIuV0UCPdqNWaY6U,1749
|
|
5
|
+
synalinks_memory/version.py,sha256=0avKLmc1a4anCnfCwmprTLqkgzO57zedhp8MtepjwSc,185
|
|
6
|
+
synalinks_memory-0.0.1.dist-info/METADATA,sha256=NXJvXT5acCZaxQoa6sVbuFhtvAPI71uByvJJHt1Qj6E,3760
|
|
7
|
+
synalinks_memory-0.0.1.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
8
|
+
synalinks_memory-0.0.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
9
|
+
synalinks_memory-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|