Skip to content

Commit 251fdf1

Browse files
feat(api): manual updates
1 parent f65b00a commit 251fdf1

30 files changed

+4065
-42
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 12
1+
configured_endpoints: 18
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/supermemory--inc%2Fsupermemory-new-f181eaeb22a42d197dbd9c45fa61bf9a9b78a91d3334fc0f841494dc73d1a203.yml
33
openapi_spec_hash: bb8262ebcdea53979cf1cafbc2c68dc8
4-
config_hash: 9b9291a6c872b063900a46386729ba3c
4+
config_hash: 2737bce9823a13e0263c0fa2701821fa

README.md

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,23 @@ response = client.search.memories(
127127
print(response.include)
128128
```
129129

130+
## File uploads
131+
132+
Request parameters that correspond to file uploads can be passed as `bytes`, or a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance or a tuple of `(filename, contents, media type)`.
133+
134+
```python
135+
from pathlib import Path
136+
from supermemory import Supermemory
137+
138+
client = Supermemory()
139+
140+
client.memories.upload_file(
141+
file=Path("/path/to/file"),
142+
)
143+
```
144+
145+
The async client uses the exact same interface. If you pass a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance, the file contents will be read asynchronously automatically.
146+
130147
## Handling errors
131148

132149
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `supermemory.APIConnectionError` is raised.
@@ -143,8 +160,8 @@ from supermemory import Supermemory
143160
client = Supermemory()
144161

145162
try:
146-
client.search.documents(
147-
q="machine learning concepts",
163+
client.memories.update(
164+
id="id",
148165
)
149166
except supermemory.APIConnectionError as e:
150167
print("The server could not be reached")
@@ -188,8 +205,8 @@ client = Supermemory(
188205
)
189206

190207
# Or, configure per-request:
191-
client.with_options(max_retries=5).search.documents(
192-
q="machine learning concepts",
208+
client.with_options(max_retries=5).memories.update(
209+
id="id",
193210
)
194211
```
195212

@@ -213,8 +230,8 @@ client = Supermemory(
213230
)
214231

215232
# Override per-request:
216-
client.with_options(timeout=5.0).search.documents(
217-
q="machine learning concepts",
233+
client.with_options(timeout=5.0).memories.update(
234+
id="id",
218235
)
219236
```
220237

@@ -256,13 +273,13 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
256273
from supermemory import Supermemory
257274

258275
client = Supermemory()
259-
response = client.search.with_raw_response.documents(
260-
q="machine learning concepts",
276+
response = client.memories.with_raw_response.update(
277+
id="id",
261278
)
262279
print(response.headers.get('X-My-Header'))
263280

264-
search = response.parse() # get the object that `search.documents()` would have returned
265-
print(search.results)
281+
memory = response.parse() # get the object that `memories.update()` would have returned
282+
print(memory.id)
266283
```
267284

268285
These methods return an [`APIResponse`](https://github.com/supermemoryai/python-sdk/tree/main/src/supermemory/_response.py) object.
@@ -276,8 +293,8 @@ The above interface eagerly reads the full response body when you make the reque
276293
To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods.
277294

278295
```python
279-
with client.search.with_streaming_response.documents(
280-
q="machine learning concepts",
296+
with client.memories.with_streaming_response.update(
297+
id="id",
281298
) as response:
282299
print(response.headers.get("X-My-Header"))
283300

api.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,49 @@
1+
# Memories
2+
3+
Types:
4+
5+
```python
6+
from supermemory.types import (
7+
MemoryUpdateResponse,
8+
MemoryListResponse,
9+
MemoryAddResponse,
10+
MemoryGetResponse,
11+
MemoryUploadFileResponse,
12+
)
13+
```
14+
15+
Methods:
16+
17+
- <code title="patch /v3/documents/{id}">client.memories.<a href="./src/supermemory/resources/memories.py">update</a>(id, \*\*<a href="src/supermemory/types/memory_update_params.py">params</a>) -> <a href="./src/supermemory/types/memory_update_response.py">MemoryUpdateResponse</a></code>
18+
- <code title="post /v3/documents/list">client.memories.<a href="./src/supermemory/resources/memories.py">list</a>(\*\*<a href="src/supermemory/types/memory_list_params.py">params</a>) -> <a href="./src/supermemory/types/memory_list_response.py">MemoryListResponse</a></code>
19+
- <code title="delete /v3/documents/{id}">client.memories.<a href="./src/supermemory/resources/memories.py">delete</a>(id) -> None</code>
20+
- <code title="post /v3/documents">client.memories.<a href="./src/supermemory/resources/memories.py">add</a>(\*\*<a href="src/supermemory/types/memory_add_params.py">params</a>) -> <a href="./src/supermemory/types/memory_add_response.py">MemoryAddResponse</a></code>
21+
- <code title="get /v3/documents/{id}">client.memories.<a href="./src/supermemory/resources/memories.py">get</a>(id) -> <a href="./src/supermemory/types/memory_get_response.py">MemoryGetResponse</a></code>
22+
- <code title="post /v3/documents/file">client.memories.<a href="./src/supermemory/resources/memories.py">upload_file</a>(\*\*<a href="src/supermemory/types/memory_upload_file_params.py">params</a>) -> <a href="./src/supermemory/types/memory_upload_file_response.py">MemoryUploadFileResponse</a></code>
23+
24+
# Documents
25+
26+
Types:
27+
28+
```python
29+
from supermemory.types import (
30+
DocumentUpdateResponse,
31+
DocumentListResponse,
32+
DocumentAddResponse,
33+
DocumentGetResponse,
34+
DocumentUploadFileResponse,
35+
)
36+
```
37+
38+
Methods:
39+
40+
- <code title="patch /v3/documents/{id}">client.documents.<a href="./src/supermemory/resources/documents.py">update</a>(id, \*\*<a href="src/supermemory/types/document_update_params.py">params</a>) -> <a href="./src/supermemory/types/document_update_response.py">DocumentUpdateResponse</a></code>
41+
- <code title="post /v3/documents/list">client.documents.<a href="./src/supermemory/resources/documents.py">list</a>(\*\*<a href="src/supermemory/types/document_list_params.py">params</a>) -> <a href="./src/supermemory/types/document_list_response.py">DocumentListResponse</a></code>
42+
- <code title="delete /v3/documents/{id}">client.documents.<a href="./src/supermemory/resources/documents.py">delete</a>(id) -> None</code>
43+
- <code title="post /v3/documents">client.documents.<a href="./src/supermemory/resources/documents.py">add</a>(\*\*<a href="src/supermemory/types/document_add_params.py">params</a>) -> <a href="./src/supermemory/types/document_add_response.py">DocumentAddResponse</a></code>
44+
- <code title="get /v3/documents/{id}">client.documents.<a href="./src/supermemory/resources/documents.py">get</a>(id) -> <a href="./src/supermemory/types/document_get_response.py">DocumentGetResponse</a></code>
45+
- <code title="post /v3/documents/file">client.documents.<a href="./src/supermemory/resources/documents.py">upload_file</a>(\*\*<a href="src/supermemory/types/document_upload_file_params.py">params</a>) -> <a href="./src/supermemory/types/document_upload_file_response.py">DocumentUploadFileResponse</a></code>
46+
147
# Search
248

349
Types:

src/supermemory/_client.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
)
2222
from ._utils import is_given, get_async_library
2323
from ._version import __version__
24-
from .resources import search, settings, connections
24+
from .resources import search, memories, settings, documents, connections
2525
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
2626
from ._exceptions import APIStatusError, SupermemoryError
2727
from ._base_client import (
@@ -43,6 +43,8 @@
4343

4444

4545
class Supermemory(SyncAPIClient):
46+
memories: memories.MemoriesResource
47+
documents: documents.DocumentsResource
4648
search: search.SearchResource
4749
settings: settings.SettingsResource
4850
connections: connections.ConnectionsResource
@@ -103,6 +105,8 @@ def __init__(
103105
_strict_response_validation=_strict_response_validation,
104106
)
105107

108+
self.memories = memories.MemoriesResource(self)
109+
self.documents = documents.DocumentsResource(self)
106110
self.search = search.SearchResource(self)
107111
self.settings = settings.SettingsResource(self)
108112
self.connections = connections.ConnectionsResource(self)
@@ -215,6 +219,8 @@ def _make_status_error(
215219

216220

217221
class AsyncSupermemory(AsyncAPIClient):
222+
memories: memories.AsyncMemoriesResource
223+
documents: documents.AsyncDocumentsResource
218224
search: search.AsyncSearchResource
219225
settings: settings.AsyncSettingsResource
220226
connections: connections.AsyncConnectionsResource
@@ -275,6 +281,8 @@ def __init__(
275281
_strict_response_validation=_strict_response_validation,
276282
)
277283

284+
self.memories = memories.AsyncMemoriesResource(self)
285+
self.documents = documents.AsyncDocumentsResource(self)
278286
self.search = search.AsyncSearchResource(self)
279287
self.settings = settings.AsyncSettingsResource(self)
280288
self.connections = connections.AsyncConnectionsResource(self)
@@ -388,27 +396,35 @@ def _make_status_error(
388396

389397
class SupermemoryWithRawResponse:
390398
def __init__(self, client: Supermemory) -> None:
399+
self.memories = memories.MemoriesResourceWithRawResponse(client.memories)
400+
self.documents = documents.DocumentsResourceWithRawResponse(client.documents)
391401
self.search = search.SearchResourceWithRawResponse(client.search)
392402
self.settings = settings.SettingsResourceWithRawResponse(client.settings)
393403
self.connections = connections.ConnectionsResourceWithRawResponse(client.connections)
394404

395405

396406
class AsyncSupermemoryWithRawResponse:
397407
def __init__(self, client: AsyncSupermemory) -> None:
408+
self.memories = memories.AsyncMemoriesResourceWithRawResponse(client.memories)
409+
self.documents = documents.AsyncDocumentsResourceWithRawResponse(client.documents)
398410
self.search = search.AsyncSearchResourceWithRawResponse(client.search)
399411
self.settings = settings.AsyncSettingsResourceWithRawResponse(client.settings)
400412
self.connections = connections.AsyncConnectionsResourceWithRawResponse(client.connections)
401413

402414

403415
class SupermemoryWithStreamedResponse:
404416
def __init__(self, client: Supermemory) -> None:
417+
self.memories = memories.MemoriesResourceWithStreamingResponse(client.memories)
418+
self.documents = documents.DocumentsResourceWithStreamingResponse(client.documents)
405419
self.search = search.SearchResourceWithStreamingResponse(client.search)
406420
self.settings = settings.SettingsResourceWithStreamingResponse(client.settings)
407421
self.connections = connections.ConnectionsResourceWithStreamingResponse(client.connections)
408422

409423

410424
class AsyncSupermemoryWithStreamedResponse:
411425
def __init__(self, client: AsyncSupermemory) -> None:
426+
self.memories = memories.AsyncMemoriesResourceWithStreamingResponse(client.memories)
427+
self.documents = documents.AsyncDocumentsResourceWithStreamingResponse(client.documents)
412428
self.search = search.AsyncSearchResourceWithStreamingResponse(client.search)
413429
self.settings = settings.AsyncSettingsResourceWithStreamingResponse(client.settings)
414430
self.connections = connections.AsyncConnectionsResourceWithStreamingResponse(client.connections)

src/supermemory/_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def assert_is_file_content(obj: object, *, key: str | None = None) -> None:
3434
if not is_file_content(obj):
3535
prefix = f"Expected entry at `{key}`" if key is not None else f"Expected file input `{obj!r}`"
3636
raise RuntimeError(
37-
f"{prefix} to be bytes, an io.IOBase instance, PathLike or a tuple but received {type(obj)} instead."
37+
f"{prefix} to be bytes, an io.IOBase instance, PathLike or a tuple but received {type(obj)} instead. See https://github.com/supermemoryai/python-sdk/tree/main#file-uploads"
3838
) from None
3939

4040

src/supermemory/resources/__init__.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
SearchResourceWithStreamingResponse,
99
AsyncSearchResourceWithStreamingResponse,
1010
)
11+
from .memories import (
12+
MemoriesResource,
13+
AsyncMemoriesResource,
14+
MemoriesResourceWithRawResponse,
15+
AsyncMemoriesResourceWithRawResponse,
16+
MemoriesResourceWithStreamingResponse,
17+
AsyncMemoriesResourceWithStreamingResponse,
18+
)
1119
from .settings import (
1220
SettingsResource,
1321
AsyncSettingsResource,
@@ -16,6 +24,14 @@
1624
SettingsResourceWithStreamingResponse,
1725
AsyncSettingsResourceWithStreamingResponse,
1826
)
27+
from .documents import (
28+
DocumentsResource,
29+
AsyncDocumentsResource,
30+
DocumentsResourceWithRawResponse,
31+
AsyncDocumentsResourceWithRawResponse,
32+
DocumentsResourceWithStreamingResponse,
33+
AsyncDocumentsResourceWithStreamingResponse,
34+
)
1935
from .connections import (
2036
ConnectionsResource,
2137
AsyncConnectionsResource,
@@ -26,6 +42,18 @@
2642
)
2743

2844
__all__ = [
45+
"MemoriesResource",
46+
"AsyncMemoriesResource",
47+
"MemoriesResourceWithRawResponse",
48+
"AsyncMemoriesResourceWithRawResponse",
49+
"MemoriesResourceWithStreamingResponse",
50+
"AsyncMemoriesResourceWithStreamingResponse",
51+
"DocumentsResource",
52+
"AsyncDocumentsResource",
53+
"DocumentsResourceWithRawResponse",
54+
"AsyncDocumentsResourceWithRawResponse",
55+
"DocumentsResourceWithStreamingResponse",
56+
"AsyncDocumentsResourceWithStreamingResponse",
2957
"SearchResource",
3058
"AsyncSearchResource",
3159
"SearchResourceWithRawResponse",

0 commit comments

Comments
 (0)