Skip to content

Commit 637811c

Browse files
feat(api): manual updates
1 parent aa29842 commit 637811c

31 files changed

+979
-1657
lines changed

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 8
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/supermemory--inc%2Fsupermemory-571ecc4d367c9f140a08728c8e3b5c1cc4f5f8ae698e325c5cbe5181c2c87bb0.yml
3-
openapi_spec_hash: b96a73f50568a58168354cb8690969e9
4-
config_hash: eb32087403f958eead829e810f5a71b8
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/supermemory--inc%2Fsupermemory-3fa2583744becce1e91ec5ad18f45d2cf17778def3a8f70537a15b08c746c2fb.yml
3+
openapi_spec_hash: bf3c5827e7ddb8b32435aeb671fe7845
4+
config_hash: b9c958a39a94966479e516e9061818be

README.md

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,43 @@ pip install --pre supermemory
2424
The full API of this library can be found in [api.md](api.md).
2525

2626
```python
27+
import os
2728
from supermemory import Supermemory
2829

2930
client = Supermemory(
30-
api_key="My API Key",
31+
api_key=os.environ.get("SUPERMEMORY_API_KEY"), # This is the default and can be omitted
3132
)
3233

33-
response = client.search.execute(
34-
q="documents related to python",
34+
memories = client.memories.list(
35+
"id",
3536
)
36-
print(response.results)
37+
print(memories.success)
3738
```
3839

40+
While you can provide an `api_key` keyword argument,
41+
we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
42+
to add `SUPERMEMORY_API_KEY="My API Key"` to your `.env` file
43+
so that your API Key is not stored in source control.
44+
3945
## Async usage
4046

4147
Simply import `AsyncSupermemory` instead of `Supermemory` and use `await` with each API call:
4248

4349
```python
50+
import os
4451
import asyncio
4552
from supermemory import AsyncSupermemory
4653

4754
client = AsyncSupermemory(
48-
api_key="My API Key",
55+
api_key=os.environ.get("SUPERMEMORY_API_KEY"), # This is the default and can be omitted
4956
)
5057

5158

5259
async def main() -> None:
53-
response = await client.search.execute(
54-
q="documents related to python",
60+
memories = await client.memories.list(
61+
"id",
5562
)
56-
print(response.results)
63+
print(memories.success)
5764

5865

5966
asyncio.run(main())
@@ -83,13 +90,11 @@ All errors inherit from `supermemory.APIError`.
8390
import supermemory
8491
from supermemory import Supermemory
8592

86-
client = Supermemory(
87-
api_key="My API Key",
88-
)
93+
client = Supermemory()
8994

9095
try:
91-
client.memory.create(
92-
content="This is a detailed article about machine learning concepts..",
96+
client.memories.list(
97+
"id",
9398
)
9499
except supermemory.APIConnectionError as e:
95100
print("The server could not be reached")
@@ -128,14 +133,13 @@ from supermemory import Supermemory
128133

129134
# Configure the default for all requests:
130135
client = Supermemory(
131-
api_key="My API Key",
132136
# default is 2
133137
max_retries=0,
134138
)
135139

136140
# Or, configure per-request:
137-
client.with_options(max_retries=5).memory.create(
138-
content="This is a detailed article about machine learning concepts..",
141+
client.with_options(max_retries=5).memories.list(
142+
"id",
139143
)
140144
```
141145

@@ -149,20 +153,18 @@ from supermemory import Supermemory
149153

150154
# Configure the default for all requests:
151155
client = Supermemory(
152-
api_key="My API Key",
153156
# 20 seconds (default is 1 minute)
154157
timeout=20.0,
155158
)
156159

157160
# More granular control:
158161
client = Supermemory(
159-
api_key="My API Key",
160162
timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0),
161163
)
162164

163165
# Override per-request:
164-
client.with_options(timeout=5.0).memory.create(
165-
content="This is a detailed article about machine learning concepts..",
166+
client.with_options(timeout=5.0).memories.list(
167+
"id",
166168
)
167169
```
168170

@@ -203,16 +205,14 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
203205
```py
204206
from supermemory import Supermemory
205207

206-
client = Supermemory(
207-
api_key="My API Key",
208-
)
209-
response = client.memory.with_raw_response.create(
210-
content="This is a detailed article about machine learning concepts..",
208+
client = Supermemory()
209+
response = client.memories.with_raw_response.list(
210+
"id",
211211
)
212212
print(response.headers.get('X-My-Header'))
213213

214-
memory = response.parse() # get the object that `memory.create()` would have returned
215-
print(memory.id)
214+
memory = response.parse() # get the object that `memories.list()` would have returned
215+
print(memory.success)
216216
```
217217

218218
These methods return an [`APIResponse`](https://github.com/supermemoryai/python-sdk/tree/main/src/supermemory/_response.py) object.
@@ -226,8 +226,8 @@ The above interface eagerly reads the full response body when you make the reque
226226
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.
227227

228228
```python
229-
with client.memory.with_streaming_response.create(
230-
content="This is a detailed article about machine learning concepts..",
229+
with client.memories.with_streaming_response.list(
230+
"id",
231231
) as response:
232232
print(response.headers.get("X-My-Header"))
233233

@@ -284,7 +284,6 @@ import httpx
284284
from supermemory import Supermemory, DefaultHttpxClient
285285

286286
client = Supermemory(
287-
api_key="My API Key",
288287
# Or use the `SUPERMEMORY_BASE_URL` env var
289288
base_url="http://my.test.server.example.com:8083",
290289
http_client=DefaultHttpxClient(
@@ -307,9 +306,7 @@ By default the library closes underlying HTTP connections whenever the client is
307306
```py
308307
from supermemory import Supermemory
309308

310-
with Supermemory(
311-
api_key="My API Key",
312-
) as client:
309+
with Supermemory() as client:
313310
# make requests here
314311
...
315312

api.md

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,50 @@
1-
# Settings
2-
3-
Types:
4-
5-
```python
6-
from supermemory.types import SettingUpdateResponse
7-
```
8-
9-
Methods:
10-
11-
- <code title="put /settings">client.settings.<a href="./src/supermemory/resources/settings.py">update</a>(\*\*<a href="src/supermemory/types/setting_update_params.py">params</a>) -> <a href="./src/supermemory/types/setting_update_response.py">SettingUpdateResponse</a></code>
12-
13-
# Memory
1+
# Memories
142

153
Types:
164

175
```python
186
from supermemory.types import (
19-
MemoryCreateResponse,
207
MemoryListResponse,
218
MemoryDeleteResponse,
9+
MemoryAddResponse,
2210
MemoryGetResponse,
2311
)
2412
```
2513

2614
Methods:
2715

28-
- <code title="post /add">client.memory.<a href="./src/supermemory/resources/memory.py">create</a>(\*\*<a href="src/supermemory/types/memory_create_params.py">params</a>) -> <a href="./src/supermemory/types/memory_create_response.py">MemoryCreateResponse</a></code>
29-
- <code title="get /memories">client.memory.<a href="./src/supermemory/resources/memory.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>
30-
- <code title="delete /delete/{id}">client.memory.<a href="./src/supermemory/resources/memory.py">delete</a>(id) -> <a href="./src/supermemory/types/memory_delete_response.py">MemoryDeleteResponse</a></code>
31-
- <code title="get /memory/{id}">client.memory.<a href="./src/supermemory/resources/memory.py">get</a>(id) -> <a href="./src/supermemory/types/memory_get_response.py">MemoryGetResponse</a></code>
16+
- <code title="delete /v3/memories/{id}">client.memories.<a href="./src/supermemory/resources/memories.py">list</a>(id) -> <a href="./src/supermemory/types/memory_list_response.py">MemoryListResponse</a></code>
17+
- <code title="get /v3/memories/{id}">client.memories.<a href="./src/supermemory/resources/memories.py">delete</a>(id) -> <a href="./src/supermemory/types/memory_delete_response.py">MemoryDeleteResponse</a></code>
18+
- <code title="post /v3/memories">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>
19+
- <code title="get /v3/memories/{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>
3220

33-
# Search
21+
# Settings
3422

3523
Types:
3624

3725
```python
38-
from supermemory.types import SearchExecuteResponse
26+
from supermemory.types import SettingUpdateResponse, SettingGetResponse
3927
```
4028

4129
Methods:
4230

43-
- <code title="post /search">client.search.<a href="./src/supermemory/resources/search.py">execute</a>(\*\*<a href="src/supermemory/types/search_execute_params.py">params</a>) -> <a href="./src/supermemory/types/search_execute_response.py">SearchExecuteResponse</a></code>
31+
- <code title="patch /v3/settings">client.settings.<a href="./src/supermemory/resources/settings.py">update</a>(\*\*<a href="src/supermemory/types/setting_update_params.py">params</a>) -> <a href="./src/supermemory/types/setting_update_response.py">SettingUpdateResponse</a></code>
32+
- <code title="get /v3/settings">client.settings.<a href="./src/supermemory/resources/settings.py">get</a>() -> <a href="./src/supermemory/types/setting_get_response.py">SettingGetResponse</a></code>
4433

45-
# Connection
34+
# Connections
4635

4736
Types:
4837

4938
```python
50-
from supermemory.types import ConnectionCreateResponse
39+
from supermemory.types import (
40+
ConnectionCreateResponse,
41+
ConnectionListResponse,
42+
ConnectionGetResponse,
43+
)
5144
```
5245

5346
Methods:
5447

55-
- <code title="get /connect/{app}">client.connection.<a href="./src/supermemory/resources/connection.py">create</a>(app, \*\*<a href="src/supermemory/types/connection_create_params.py">params</a>) -> <a href="./src/supermemory/types/connection_create_response.py">ConnectionCreateResponse</a></code>
56-
- <code title="get /connections/{connectionId}">client.connection.<a href="./src/supermemory/resources/connection.py">retrieve</a>(connection_id) -> None</code>
48+
- <code title="post /v3/connections/{provider}">client.connections.<a href="./src/supermemory/resources/connections.py">create</a>(provider) -> <a href="./src/supermemory/types/connection_create_response.py">ConnectionCreateResponse</a></code>
49+
- <code title="get /v3/connections">client.connections.<a href="./src/supermemory/resources/connections.py">list</a>() -> <a href="./src/supermemory/types/connection_list_response.py">ConnectionListResponse</a></code>
50+
- <code title="get /v3/connections/{connectionId}">client.connections.<a href="./src/supermemory/resources/connections.py">get</a>(connection_id) -> <a href="./src/supermemory/types/connection_get_response.py">ConnectionGetResponse</a></code>

src/supermemory/_client.py

Lines changed: 31 additions & 27 deletions
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 memory, search, settings, connection
24+
from .resources import memories, settings, connections
2525
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
2626
from ._exceptions import APIStatusError, SupermemoryError
2727
from ._base_client import (
@@ -43,10 +43,9 @@
4343

4444

4545
class Supermemory(SyncAPIClient):
46+
memories: memories.MemoriesResource
4647
settings: settings.SettingsResource
47-
memory: memory.MemoryResource
48-
search: search.SearchResource
49-
connection: connection.ConnectionResource
48+
connections: connections.ConnectionsResource
5049
with_raw_response: SupermemoryWithRawResponse
5150
with_streaming_response: SupermemoryWithStreamedResponse
5251

@@ -91,7 +90,7 @@ def __init__(
9190
if base_url is None:
9291
base_url = os.environ.get("SUPERMEMORY_BASE_URL")
9392
if base_url is None:
94-
base_url = f"https://v2.api.supermemory.ai"
93+
base_url = f"https://api.supermemory.ai/"
9594

9695
super().__init__(
9796
version=__version__,
@@ -104,10 +103,9 @@ def __init__(
104103
_strict_response_validation=_strict_response_validation,
105104
)
106105

106+
self.memories = memories.MemoriesResource(self)
107107
self.settings = settings.SettingsResource(self)
108-
self.memory = memory.MemoryResource(self)
109-
self.search = search.SearchResource(self)
110-
self.connection = connection.ConnectionResource(self)
108+
self.connections = connections.ConnectionsResource(self)
111109
self.with_raw_response = SupermemoryWithRawResponse(self)
112110
self.with_streaming_response = SupermemoryWithStreamedResponse(self)
113111

@@ -116,6 +114,12 @@ def __init__(
116114
def qs(self) -> Querystring:
117115
return Querystring(array_format="comma")
118116

117+
@property
118+
@override
119+
def auth_headers(self) -> dict[str, str]:
120+
api_key = self.api_key
121+
return {"Authorization": f"Bearer {api_key}"}
122+
119123
@property
120124
@override
121125
def default_headers(self) -> dict[str, str | Omit]:
@@ -211,10 +215,9 @@ def _make_status_error(
211215

212216

213217
class AsyncSupermemory(AsyncAPIClient):
218+
memories: memories.AsyncMemoriesResource
214219
settings: settings.AsyncSettingsResource
215-
memory: memory.AsyncMemoryResource
216-
search: search.AsyncSearchResource
217-
connection: connection.AsyncConnectionResource
220+
connections: connections.AsyncConnectionsResource
218221
with_raw_response: AsyncSupermemoryWithRawResponse
219222
with_streaming_response: AsyncSupermemoryWithStreamedResponse
220223

@@ -259,7 +262,7 @@ def __init__(
259262
if base_url is None:
260263
base_url = os.environ.get("SUPERMEMORY_BASE_URL")
261264
if base_url is None:
262-
base_url = f"https://v2.api.supermemory.ai"
265+
base_url = f"https://api.supermemory.ai/"
263266

264267
super().__init__(
265268
version=__version__,
@@ -272,10 +275,9 @@ def __init__(
272275
_strict_response_validation=_strict_response_validation,
273276
)
274277

278+
self.memories = memories.AsyncMemoriesResource(self)
275279
self.settings = settings.AsyncSettingsResource(self)
276-
self.memory = memory.AsyncMemoryResource(self)
277-
self.search = search.AsyncSearchResource(self)
278-
self.connection = connection.AsyncConnectionResource(self)
280+
self.connections = connections.AsyncConnectionsResource(self)
279281
self.with_raw_response = AsyncSupermemoryWithRawResponse(self)
280282
self.with_streaming_response = AsyncSupermemoryWithStreamedResponse(self)
281283

@@ -284,6 +286,12 @@ def __init__(
284286
def qs(self) -> Querystring:
285287
return Querystring(array_format="comma")
286288

289+
@property
290+
@override
291+
def auth_headers(self) -> dict[str, str]:
292+
api_key = self.api_key
293+
return {"Authorization": f"Bearer {api_key}"}
294+
287295
@property
288296
@override
289297
def default_headers(self) -> dict[str, str | Omit]:
@@ -380,34 +388,30 @@ def _make_status_error(
380388

381389
class SupermemoryWithRawResponse:
382390
def __init__(self, client: Supermemory) -> None:
391+
self.memories = memories.MemoriesResourceWithRawResponse(client.memories)
383392
self.settings = settings.SettingsResourceWithRawResponse(client.settings)
384-
self.memory = memory.MemoryResourceWithRawResponse(client.memory)
385-
self.search = search.SearchResourceWithRawResponse(client.search)
386-
self.connection = connection.ConnectionResourceWithRawResponse(client.connection)
393+
self.connections = connections.ConnectionsResourceWithRawResponse(client.connections)
387394

388395

389396
class AsyncSupermemoryWithRawResponse:
390397
def __init__(self, client: AsyncSupermemory) -> None:
398+
self.memories = memories.AsyncMemoriesResourceWithRawResponse(client.memories)
391399
self.settings = settings.AsyncSettingsResourceWithRawResponse(client.settings)
392-
self.memory = memory.AsyncMemoryResourceWithRawResponse(client.memory)
393-
self.search = search.AsyncSearchResourceWithRawResponse(client.search)
394-
self.connection = connection.AsyncConnectionResourceWithRawResponse(client.connection)
400+
self.connections = connections.AsyncConnectionsResourceWithRawResponse(client.connections)
395401

396402

397403
class SupermemoryWithStreamedResponse:
398404
def __init__(self, client: Supermemory) -> None:
405+
self.memories = memories.MemoriesResourceWithStreamingResponse(client.memories)
399406
self.settings = settings.SettingsResourceWithStreamingResponse(client.settings)
400-
self.memory = memory.MemoryResourceWithStreamingResponse(client.memory)
401-
self.search = search.SearchResourceWithStreamingResponse(client.search)
402-
self.connection = connection.ConnectionResourceWithStreamingResponse(client.connection)
407+
self.connections = connections.ConnectionsResourceWithStreamingResponse(client.connections)
403408

404409

405410
class AsyncSupermemoryWithStreamedResponse:
406411
def __init__(self, client: AsyncSupermemory) -> None:
412+
self.memories = memories.AsyncMemoriesResourceWithStreamingResponse(client.memories)
407413
self.settings = settings.AsyncSettingsResourceWithStreamingResponse(client.settings)
408-
self.memory = memory.AsyncMemoryResourceWithStreamingResponse(client.memory)
409-
self.search = search.AsyncSearchResourceWithStreamingResponse(client.search)
410-
self.connection = connection.AsyncConnectionResourceWithStreamingResponse(client.connection)
414+
self.connections = connections.AsyncConnectionsResourceWithStreamingResponse(client.connections)
411415

412416

413417
Client = Supermemory

0 commit comments

Comments
 (0)