Skip to content

Commit fda6f9f

Browse files
feat(api): api update
1 parent 2403f1d commit fda6f9f

File tree

4 files changed

+18
-47
lines changed

4 files changed

+18
-47
lines changed

.stats.yml

Lines changed: 2 additions & 2 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-17320f0488a9b933245c77e962932c0323d8e940123f2571f93e476c5b5c2d18.yml
3-
openapi_spec_hash: 8c13c404e5eb19f455dc7155c7f93e45
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/supermemory--inc%2Fsupermemory-aebc3d012c87df9d5cb4d651a374fceefb5154e74c70f51d927c76b923267a85.yml
3+
openapi_spec_hash: 98493a823305edac2c711cd052971f3d
44
config_hash: eb32087403f958eead829e810f5a71b8

README.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ 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
2827
from supermemory import Supermemory
2928

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

3433
response = client.search.execute(
@@ -37,22 +36,16 @@ response = client.search.execute(
3736
print(response.results)
3837
```
3938

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-
4539
## Async usage
4640

4741
Simply import `AsyncSupermemory` instead of `Supermemory` and use `await` with each API call:
4842

4943
```python
50-
import os
5144
import asyncio
5245
from supermemory import AsyncSupermemory
5346

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

5851

@@ -90,7 +83,9 @@ All errors inherit from `supermemory.APIError`.
9083
import supermemory
9184
from supermemory import Supermemory
9285

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

9590
try:
9691
client.memory.create(
@@ -133,6 +128,7 @@ from supermemory import Supermemory
133128

134129
# Configure the default for all requests:
135130
client = Supermemory(
131+
api_key="My API Key",
136132
# default is 2
137133
max_retries=0,
138134
)
@@ -153,12 +149,14 @@ from supermemory import Supermemory
153149

154150
# Configure the default for all requests:
155151
client = Supermemory(
152+
api_key="My API Key",
156153
# 20 seconds (default is 1 minute)
157154
timeout=20.0,
158155
)
159156

160157
# More granular control:
161158
client = Supermemory(
159+
api_key="My API Key",
162160
timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0),
163161
)
164162

@@ -205,7 +203,9 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
205203
```py
206204
from supermemory import Supermemory
207205

208-
client = Supermemory()
206+
client = Supermemory(
207+
api_key="My API Key",
208+
)
209209
response = client.memory.with_raw_response.create(
210210
content="This is a detailed article about machine learning concepts...",
211211
)
@@ -284,6 +284,7 @@ import httpx
284284
from supermemory import Supermemory, DefaultHttpxClient
285285

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

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

src/supermemory/_client.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,6 @@ def __init__(
116116
def qs(self) -> Querystring:
117117
return Querystring(array_format="comma")
118118

119-
@property
120-
@override
121-
def auth_headers(self) -> dict[str, str]:
122-
api_key = self.api_key
123-
return {"X-API-Key": api_key}
124-
125119
@property
126120
@override
127121
def default_headers(self) -> dict[str, str | Omit]:
@@ -290,12 +284,6 @@ def __init__(
290284
def qs(self) -> Querystring:
291285
return Querystring(array_format="comma")
292286

293-
@property
294-
@override
295-
def auth_headers(self) -> dict[str, str]:
296-
api_key = self.api_key
297-
return {"X-API-Key": api_key}
298-
299287
@property
300288
@override
301289
def default_headers(self) -> dict[str, str | Omit]:

tests/test_client.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from supermemory._utils import maybe_transform
2727
from supermemory._models import BaseModel, FinalRequestOptions
2828
from supermemory._constants import RAW_RESPONSE_HEADER
29-
from supermemory._exceptions import APIStatusError, APITimeoutError, SupermemoryError, APIResponseValidationError
29+
from supermemory._exceptions import APIStatusError, APITimeoutError, APIResponseValidationError
3030
from supermemory._base_client import (
3131
DEFAULT_TIMEOUT,
3232
HTTPX_DEFAULT_TIMEOUT,
@@ -336,16 +336,6 @@ def test_default_headers_option(self) -> None:
336336
assert request.headers.get("x-foo") == "stainless"
337337
assert request.headers.get("x-stainless-lang") == "my-overriding-header"
338338

339-
def test_validate_headers(self) -> None:
340-
client = Supermemory(base_url=base_url, api_key=api_key, _strict_response_validation=True)
341-
request = client._build_request(FinalRequestOptions(method="get", url="/foo"))
342-
assert request.headers.get("X-API-Key") == api_key
343-
344-
with pytest.raises(SupermemoryError):
345-
with update_env(**{"SUPERMEMORY_API_KEY": Omit()}):
346-
client2 = Supermemory(base_url=base_url, api_key=None, _strict_response_validation=True)
347-
_ = client2
348-
349339
def test_default_query_option(self) -> None:
350340
client = Supermemory(
351341
base_url=base_url, api_key=api_key, _strict_response_validation=True, default_query={"query_param": "bar"}
@@ -1128,16 +1118,6 @@ def test_default_headers_option(self) -> None:
11281118
assert request.headers.get("x-foo") == "stainless"
11291119
assert request.headers.get("x-stainless-lang") == "my-overriding-header"
11301120

1131-
def test_validate_headers(self) -> None:
1132-
client = AsyncSupermemory(base_url=base_url, api_key=api_key, _strict_response_validation=True)
1133-
request = client._build_request(FinalRequestOptions(method="get", url="/foo"))
1134-
assert request.headers.get("X-API-Key") == api_key
1135-
1136-
with pytest.raises(SupermemoryError):
1137-
with update_env(**{"SUPERMEMORY_API_KEY": Omit()}):
1138-
client2 = AsyncSupermemory(base_url=base_url, api_key=None, _strict_response_validation=True)
1139-
_ = client2
1140-
11411121
def test_default_query_option(self) -> None:
11421122
client = AsyncSupermemory(
11431123
base_url=base_url, api_key=api_key, _strict_response_validation=True, default_query={"query_param": "bar"}

0 commit comments

Comments
 (0)