Official Python client for the MemorySync API.
Project description
memorysync
Official Python client for the MemorySync API. Sync and async, no surprises.
pip install memorysync
Quick start
from memorysync import MemorySyncClient
ms = MemorySyncClient(
api_key="...",
base_url="https://api.memorysync.dev",
project_id="proj_xxxxxxxxxxxxxxxx", # optional
end_user_id="user_42", # optional
)
ms.add("User prefers dark mode.")
result = ms.query("ui preferences", k=5)
for m in result.memories:
print(m.id, m.text)
Async usage
import asyncio
from memorysync import AsyncMemorySyncClient
async def main():
async with AsyncMemorySyncClient(api_key="...", base_url="...") as ms:
result = await ms.query("ui preferences", k=5)
print(result.memories)
asyncio.run(main())
Use MemorySyncClient as a context manager when you want deterministic
connection cleanup:
with MemorySyncClient(api_key="...", base_url="...") as ms:
ms.add("...")
Configuration
| Argument | Required | Description |
|---|---|---|
api_key |
yes | Sent as X-API-Key. Provision in your MemorySync dashboard. |
base_url |
yes | Deployment URL of your MemorySync instance. |
project_id |
no | Pin every request to a project (X-Project-ID). Format: proj_ + 16 hex chars. |
end_user_id |
no | Identify which of your users this client speaks for (X-End-User-ID). |
timeout |
no | Per-request timeout in seconds. Default 30.0. |
transport |
no | Inject a custom httpx transport (tests, retries, proxies). |
end_user_id can also be passed per-call on add() to override the client default.
Methods
Every method maps 1:1 to a real HTTP route. The two clients share the same
surface; only the call style differs (sync vs await).
| Method | Route |
|---|---|
add(text, **opts) |
POST /memory/add |
bulk_add(items, *, deduplicate=True) |
POST /memory/bulk-add |
query(query, *, k=None, ...) |
POST /memory/query |
get(memory_id) |
GET /memory/{id} |
update(memory_id, **fields) |
PATCH /memory/{id} |
forget(memory_ids, *, reason=None) |
DELETE /memory/forget |
summarize(memory_ids, *, lossless=False) |
POST /memory/summarize |
compose(prompt_template, *, recall_k=None) |
POST /memory/compose |
export_all() |
GET /memory/export |
create_relation(from_id, **opts) |
POST /memory/{id}/relations |
add returns one of two shapes
add() runs through MemorySync's extraction pipeline, so input that carries no
high-value content is intentionally skipped. Branch on the type of the result:
from memorysync import AddSkippedResponse, Memory
result = ms.add("User prefers dark mode.")
if isinstance(result, AddSkippedResponse):
print("skipped:", result.reason)
else:
assert isinstance(result, Memory)
print(result.id, result.text)
Errors
Every non-2xx response raises a typed subclass of MemorySyncError:
| Class | When |
|---|---|
AuthError |
401 / 403 — bad key, missing scope. |
ValidationError |
400 / 409 / 422. |
NotFoundError |
404 — record not visible to the caller. |
RateLimitError |
429 — read err.retry_after_seconds. |
ServerError |
5xx. |
MemorySyncError |
Network errors, timeouts, anything else. |
Every error carries status_code, response, and the server-issued
request_id (when present) for support escalation.
import time
from memorysync import RateLimitError
try:
ms.add("...")
except RateLimitError as e:
time.sleep(e.retry_after_seconds)
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file memorysync-1.0.0.tar.gz.
File metadata
- Download URL: memorysync-1.0.0.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ba4b064b59000e135fb0ffe66c9c7d2d63831399c7a129aa75252df5825074f
|
|
| MD5 |
da37ceef4297446e543c3d7c0f8d1e3b
|
|
| BLAKE2b-256 |
79e7f8f11afab260aee26ac801ef0e8d3055c663d291706c56a850c823fd23a2
|
File details
Details for the file memorysync-1.0.0-py3-none-any.whl.
File metadata
- Download URL: memorysync-1.0.0-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5fe2fb1cf43aea032b0a445cb18da5339babddf9b7c2cdf2d2007735fd4024c
|
|
| MD5 |
741ee97aae9f1c28c568b833d42b91e0
|
|
| BLAKE2b-256 |
8270aeda652a77ee4c35148cd7deb1ff13a3d5f40bba212d847ba074ddc74c98
|