The official Python library for the Supermemory v5 API, with sync and async clients built on httpx.
Upgrading from 3.x? v5 moves to the namespace-first v5 API. See MIGRATION.md.
Installation
pip install supermemory
Usage
from supermemory import Supermemory
client = Supermemory() # reads SUPERMEMORY_API_KEY; or Supermemory(api_key="...")
client.add("user_alex", content="Alex prefers morning meetings.", id="pref-1")
response = client.search("user_alex", query="when does alex like to meet?", limit=5)
for result in response.results:
print(result)
Every content operation is scoped to a namespace (a user ID, project ID, or anything you want to isolate memories by), passed as the first argument.
The same filter shape works for client.list(...) and client.profile(...).
Listing
page = client.list("user_alex", "documents", page=1, limit=50, sort="createdAt", order="desc")
for document in page.documents or []:
print(document.id, document.title)
print(page.pagination)
File uploads
with open("notes.pdf", "rb") as f:
client.documents.upload_file("user_alex", file=f)
Errors
Same exception classes as 3.x. Non-2xx responses raise a subclass of supermemory.APIStatusError with status_code, body, message, request, and response. Network failures raise APIConnectionError (APITimeoutError for timeouts):
import supermemory
from supermemory import Supermemory
client = Supermemory()
try:
client.documents.get("user_alex", "missing-id")
except supermemory.NotFoundError:
...
except supermemory.RateLimitError as e:
print(e.response.headers.get("retry-after"))
except supermemory.APIStatusError as e:
print(e.status_code, e.body)
except supermemory.APIConnectionError:
...
Status
Error
400
BadRequestError
401
AuthenticationError
403
PermissionDeniedError
404
NotFoundError
409
ConflictError
422
UnprocessableEntityError
429
RateLimitError
>=500
InternalServerError
Retries, timeouts, and per-request options
Connection errors, 408, 429, and 5xx responses are retried twice with exponential backoff, and requests time out after 60 seconds (5 seconds to connect). All of these can be set on the client, or for one request with with_options:
The SDK is generated from the live v5 OpenAPI spec with Fern's open-source Python generator, run locally in Docker. No hosted codegen service is involved. Don't edit src/supermemory by hand; CI fails if it doesn't match a fresh generation.
scripts/generate fetches the spec, names its schemas, runs Fern, then layers custom/ on top.
scripts/generate # fetch /v5/openapi and regenerate (needs Docker, bun, uv)
SKIP_FETCH=1 scripts/generate # regenerate from the committed fern/openapi.json
uv run --group dev pytest # offline tests, including every snippet in README.md and MIGRATION.md
SUPERMEMORY_LIVE_API_KEY=... uv run --group dev pytest tests/live # against the real API
When the API deploy sends openapi-updated (or on the daily backstop run), Generate SDK regenerates. If the SDK changed, it bumps the version and opens a PR with the tests already run.
Merging a PR that changes the version in pyproject.toml publishes it to PyPI and creates a GitHub release.
To cut a specific version, run Generate SDK manually with version set.
Alternatives
Use instead of supermemory: tools that do the same job, closest first.