You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
***tests:** fix: tests which call HTTP endpoints directly with the example parameters ([f9bf3c1](https://github.com/supermemoryai/python-sdk/commit/f9bf3c135c6a6236c8ef0ee5d538843021448b9d))
41
+
42
+
43
+
### Chores
44
+
45
+
***ci:** enable for pull requests ([ec1b12b](https://github.com/supermemoryai/python-sdk/commit/ec1b12b9447ff582d80a0dedf75dc5c924aee6e4))
***tests:** add tests for httpx client instantiation & proxies ([a462f22](https://github.com/supermemoryai/python-sdk/commit/a462f2240dac23bf780f540ba39da3febbc561e7))
53
+
***tests:** run tests in parallel ([79f6359](https://github.com/supermemoryai/python-sdk/commit/79f6359beb267f85e273a5a3017283d9e231e78a))
54
+
***tests:** skip some failing tests on the latest python versions ([394e639](https://github.com/supermemoryai/python-sdk/commit/394e639fb904cd4c27b299f5960fd2f02f159b10))
The Supermemory Python library provides convenient access to the Supermemory REST API from any Python 3.8+
6
6
application. The library includes type definitions for all request params and response fields,
@@ -31,10 +31,10 @@ client = Supermemory(
31
31
api_key=os.environ.get("SUPERMEMORY_API_KEY"), # This is the default and can be omitted
32
32
)
33
33
34
-
response = client.search.execute(
35
-
q="documents related to python",
34
+
response = client.memories.add(
35
+
content="This is a detailed article about machine learning concepts...",
36
36
)
37
-
print(response.results)
37
+
print(response.id)
38
38
```
39
39
40
40
While you can provide an `api_key` keyword argument,
@@ -57,42 +57,59 @@ client = AsyncSupermemory(
57
57
58
58
59
59
asyncdefmain() -> None:
60
-
response =await client.search.execute(
61
-
q="documents related to python",
60
+
response =await client.memories.add(
61
+
content="This is a detailed article about machine learning concepts...",
62
62
)
63
-
print(response.results)
63
+
print(response.id)
64
64
65
65
66
66
asyncio.run(main())
67
67
```
68
68
69
69
Functionality between the synchronous and asynchronous clients is otherwise identical.
70
70
71
-
## Using types
72
-
73
-
Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev) which also provide helper methods for things like:
71
+
### With aiohttp
74
72
75
-
- Serializing back into JSON, `model.to_json()`
76
-
- Converting to a dictionary, `model.to_dict()`
73
+
By default, the async client uses `httpx` for HTTP requests. However, for improved concurrency performance you may also use `aiohttp` as the HTTP backend.
77
74
78
-
Typed requests and responses provide autocomplete and documentation within your editor. If you would like to see type errors in VS Code to help catch bugs earlier, set `python.analysis.typeCheckingMode` to `basic`.
75
+
You can enable this by installing `aiohttp`:
79
76
80
-
## File uploads
77
+
```sh
78
+
# install from PyPI
79
+
pip install --pre supermemory[aiohttp]
80
+
```
81
81
82
-
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)`.
82
+
Then you can enable it by instantiating the client with `http_client=DefaultAioHttpClient()`:
83
83
84
84
```python
85
-
from pathlib import Path
86
-
from supermemory import Supermemory
85
+
import os
86
+
import asyncio
87
+
from supermemory import DefaultAioHttpClient
88
+
from supermemory import AsyncSupermemory
87
89
88
-
client = Supermemory()
89
90
90
-
client.memories.upload_file(
91
-
file=Path("/path/to/file"),
92
-
)
91
+
asyncdefmain() -> None:
92
+
asyncwith AsyncSupermemory(
93
+
api_key=os.environ.get("SUPERMEMORY_API_KEY"), # This is the default and can be omitted
94
+
http_client=DefaultAioHttpClient(),
95
+
) as client:
96
+
response =await client.memories.add(
97
+
content="This is a detailed article about machine learning concepts...",
98
+
)
99
+
print(response.id)
100
+
101
+
102
+
asyncio.run(main())
93
103
```
94
104
95
-
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.
105
+
## Using types
106
+
107
+
Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev) which also provide helper methods for things like:
108
+
109
+
- Serializing back into JSON, `model.to_json()`
110
+
- Converting to a dictionary, `model.to_dict()`
111
+
112
+
Typed requests and responses provide autocomplete and documentation within your editor. If you would like to see type errors in VS Code to help catch bugs earlier, set `python.analysis.typeCheckingMode` to `basic`.
0 commit comments