Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "3.0.0-alpha.25"
".": "3.0.0-alpha.26"
}
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 16
configured_endpoints: 18
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/supermemory--inc%2Fsupermemory-new-d52acd1a525b4bfe9f4befcc3a645f5d1289d75e7bad999cf1330e539b2ed84e.yml
openapi_spec_hash: c34df5406cfa4d245812d30f99d28116
config_hash: be10c837d5319a33f30809a3ec223caf
config_hash: 9b9291a6c872b063900a46386729ba3c
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 3.0.0-alpha.26 (2025-08-15)

Full Changelog: [v3.0.0-alpha.25...v3.0.0-alpha.26](https://github.com/supermemoryai/python-sdk/compare/v3.0.0-alpha.25...v3.0.0-alpha.26)

### Features

* **api:** manual updates ([c2623b2](https://github.com/supermemoryai/python-sdk/commit/c2623b2b645eefd7e2cbb5027eb5a46cee7b62eb))
* **api:** manual updates ([9e373ef](https://github.com/supermemoryai/python-sdk/commit/9e373ef0b585eb15cb04b95a1bab46c8c102970c))
* **api:** manual updates ([fa75aff](https://github.com/supermemoryai/python-sdk/commit/fa75affffb701259be14445da95c77a1cdde512b))

## 3.0.0-alpha.25 (2025-08-15)

Full Changelog: [v3.0.0-alpha.24...v3.0.0-alpha.25](https://github.com/supermemoryai/python-sdk/compare/v3.0.0-alpha.24...v3.0.0-alpha.25)
Expand Down
39 changes: 36 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ client = Supermemory(
api_key=os.environ.get("SUPERMEMORY_API_KEY"), # This is the default and can be omitted
)

response = client.search.execute(
response = client.search.documents(
q="documents related to python",
)
print(response.results)
Expand All @@ -58,7 +58,7 @@ client = AsyncSupermemory(


async def main() -> None:
response = await client.search.execute(
response = await client.search.documents(
q="documents related to python",
)
print(response.results)
Expand Down Expand Up @@ -93,7 +93,7 @@ async def main() -> None:
api_key="My API Key",
http_client=DefaultAioHttpClient(),
) as client:
response = await client.search.execute(
response = await client.search.documents(
q="documents related to python",
)
print(response.results)
Expand All @@ -111,6 +111,39 @@ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typ

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`.

## Nested params

Nested parameters are dictionaries, typed using `TypedDict`, for example:

```python
from supermemory import Supermemory

client = Supermemory()

response = client.search.memories(
q="machine learning concepts",
include={},
)
print(response.include)
```

## File uploads

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)`.

```python
from pathlib import Path
from supermemory import Supermemory

client = Supermemory()

client.memories.upload_file(
file=Path("/path/to/file"),
)
```

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.

## Handling errors

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.
Expand Down
6 changes: 5 additions & 1 deletion api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ from supermemory.types import (
MemoryListResponse,
MemoryAddResponse,
MemoryGetResponse,
MemoryUploadFileResponse,
)
```

Expand All @@ -18,18 +19,21 @@ Methods:
- <code title="delete /v3/memories/{id}">client.memories.<a href="./src/supermemory/resources/memories.py">delete</a>(id) -> None</code>
- <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>
- <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>
- <code title="post /v3/memories/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>

# Search

Types:

```python
from supermemory.types import SearchExecuteResponse
from supermemory.types import SearchDocumentsResponse, SearchExecuteResponse, SearchMemoriesResponse
```

Methods:

- <code title="post /v3/search">client.search.<a href="./src/supermemory/resources/search.py">documents</a>(\*\*<a href="src/supermemory/types/search_documents_params.py">params</a>) -> <a href="./src/supermemory/types/search_documents_response.py">SearchDocumentsResponse</a></code>
- <code title="post /v3/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>
- <code title="post /v4/search">client.search.<a href="./src/supermemory/resources/search.py">memories</a>(\*\*<a href="src/supermemory/types/search_memories_params.py">params</a>) -> <a href="./src/supermemory/types/search_memories_response.py">SearchMemoriesResponse</a></code>

# Settings

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "supermemory"
version = "3.0.0-alpha.25"
version = "3.0.0-alpha.26"
description = "The official Python library for the supermemory API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion src/supermemory/_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def assert_is_file_content(obj: object, *, key: str | None = None) -> None:
if not is_file_content(obj):
prefix = f"Expected entry at `{key}`" if key is not None else f"Expected file input `{obj!r}`"
raise RuntimeError(
f"{prefix} to be bytes, an io.IOBase instance, PathLike or a tuple but received {type(obj)} instead."
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"
) from None


Expand Down
2 changes: 1 addition & 1 deletion src/supermemory/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

__title__ = "supermemory"
__version__ = "3.0.0-alpha.25" # x-release-please-version
__version__ = "3.0.0-alpha.26" # x-release-please-version
111 changes: 107 additions & 4 deletions src/supermemory/resources/memories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

from __future__ import annotations

from typing import Dict, List, Union
from typing import Dict, List, Union, Mapping, cast
from typing_extensions import Literal

import httpx

from ..types import memory_add_params, memory_list_params, memory_update_params
from .._types import NOT_GIVEN, Body, Query, Headers, NoneType, NotGiven
from .._utils import maybe_transform, async_maybe_transform
from ..types import memory_add_params, memory_list_params, memory_update_params, memory_upload_file_params
from .._types import NOT_GIVEN, Body, Query, Headers, NoneType, NotGiven, FileTypes
from .._utils import extract_files, maybe_transform, deepcopy_minimal, async_maybe_transform
from .._compat import cached_property
from .._resource import SyncAPIResource, AsyncAPIResource
from .._response import (
Expand All @@ -23,6 +23,7 @@
from ..types.memory_get_response import MemoryGetResponse
from ..types.memory_list_response import MemoryListResponse
from ..types.memory_update_response import MemoryUpdateResponse
from ..types.memory_upload_file_response import MemoryUploadFileResponse

__all__ = ["MemoriesResource", "AsyncMemoriesResource"]

Expand Down Expand Up @@ -305,6 +306,51 @@ def get(
cast_to=MemoryGetResponse,
)

def upload_file(
self,
*,
file: FileTypes,
container_tags: str | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> MemoryUploadFileResponse:
"""
Upload a file to be processed

Args:
extra_headers: Send extra headers

extra_query: Add additional query parameters to the request

extra_body: Add additional JSON properties to the request

timeout: Override the client-level default timeout for this request, in seconds
"""
body = deepcopy_minimal(
{
"file": file,
"container_tags": container_tags,
}
)
files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return self._post(
"/v3/memories/file",
body=maybe_transform(body, memory_upload_file_params.MemoryUploadFileParams),
files=files,
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=MemoryUploadFileResponse,
)


class AsyncMemoriesResource(AsyncAPIResource):
@cached_property
Expand Down Expand Up @@ -584,6 +630,51 @@ async def get(
cast_to=MemoryGetResponse,
)

async def upload_file(
self,
*,
file: FileTypes,
container_tags: str | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> MemoryUploadFileResponse:
"""
Upload a file to be processed

Args:
extra_headers: Send extra headers

extra_query: Add additional query parameters to the request

extra_body: Add additional JSON properties to the request

timeout: Override the client-level default timeout for this request, in seconds
"""
body = deepcopy_minimal(
{
"file": file,
"container_tags": container_tags,
}
)
files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return await self._post(
"/v3/memories/file",
body=await async_maybe_transform(body, memory_upload_file_params.MemoryUploadFileParams),
files=files,
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=MemoryUploadFileResponse,
)


class MemoriesResourceWithRawResponse:
def __init__(self, memories: MemoriesResource) -> None:
Expand All @@ -604,6 +695,9 @@ def __init__(self, memories: MemoriesResource) -> None:
self.get = to_raw_response_wrapper(
memories.get,
)
self.upload_file = to_raw_response_wrapper(
memories.upload_file,
)


class AsyncMemoriesResourceWithRawResponse:
Expand All @@ -625,6 +719,9 @@ def __init__(self, memories: AsyncMemoriesResource) -> None:
self.get = async_to_raw_response_wrapper(
memories.get,
)
self.upload_file = async_to_raw_response_wrapper(
memories.upload_file,
)


class MemoriesResourceWithStreamingResponse:
Expand All @@ -646,6 +743,9 @@ def __init__(self, memories: MemoriesResource) -> None:
self.get = to_streamed_response_wrapper(
memories.get,
)
self.upload_file = to_streamed_response_wrapper(
memories.upload_file,
)


class AsyncMemoriesResourceWithStreamingResponse:
Expand All @@ -667,3 +767,6 @@ def __init__(self, memories: AsyncMemoriesResource) -> None:
self.get = async_to_streamed_response_wrapper(
memories.get,
)
self.upload_file = async_to_streamed_response_wrapper(
memories.upload_file,
)
Loading