SDKs · Python
Python Memory Client
Build against the ten public memory methods, their typed results, and explicit user scope. Use the API Reference when you need every field and status outcome.
Configure the client
client.py
import osfrom memorysync import MemorySyncClientclient = MemorySyncClient(api_key=os.environ["MEMORYSYNC_API_KEY"],base_url="https://api.memorysync.io",project_id=os.environ["MEMORYSYNC_PROJECT_ID"],end_user_id="usr_7f3a9c2e",)
| Argument | Required | Purpose |
|---|---|---|
api_key | Yes | Server-side memory API credential. |
base_url | Yes | MemorySync HTTPS base URL. |
project_id | By application scope | Selects the trusted project context. |
end_user_id | For user-scoped memory calls | Stable opaque application-user identifier. |
timeout | No | Request timeout in seconds; defaults to 30. |
transport | No | Inject an httpx transport when your application requires one. |
All memory methods
| Method | Returns | Use |
|---|---|---|
add(text, ...) | Memory | AddSkippedResponse | Store one memory candidate. |
bulk_add(items, deduplicate=True) | BulkAddResponse | Submit 1–50 independent items and inspect each outcome. |
query(query, ...) | QueryResponse | Retrieve up to the requested result window. |
get(memory_id) | Memory | Read one known record. |
update(memory_id, ...) | Memory | Replace supported descriptive fields. |
forget(memory_ids, reason=None) | list[int] | Remove selected records and inspect confirmed IDs. |
summarize(memory_ids, lossless=False) | Memory | Create a summary record from selected IDs. |
compose(prompt_template, ...) | ComposeResponse | Receive a composed prompt and usage fields. |
export_all() | ExportResponse | Read the authenticated principal export bundle. |
create_relation(from_memory_id, ...) | Relation | Create a documented relationship between records. |
Branch on Add outcomes
add_memory.py
from memorysync import AddSkippedResponseresult = client.add("The user prefers dark mode.",source="settings",metadata={"screen": "appearance"},)if isinstance(result, AddSkippedResponse):print("not created", result.reason)else:print("created", result.id, result.text)
Reconcile every bulk item
bulk_add.py
from memorysync import BulkAddItemresponse = client.bulk_add([BulkAddItem(text="The launch is Friday.", tags=["plan"]),BulkAddItem(text="The release needs legal approval.", tags=["constraint"]),])for item in response.results:print(item.index, item.status, item.memory_ids, item.reason)
Retrieve and maintain records
retrieve_and_update.py
response = client.query("What constraints apply to the launch?",k=5,filters={"tags": ["constraint"]},)for memory in response.memories:current = client.get(memory.id)updated = client.update(current.id, tags=["constraint", "reviewed"])print(updated.id, updated.tags)
Authorize destructive operations
forget.py
memory_ids = [101, 102]deleted_ids = client.forget(memory_ids, reason="user_request")if set(deleted_ids) != set(memory_ids):print("Reconcile the IDs that were not confirmed")
Close the client
lifecycle.py
from memorysync import MemorySyncClientwith MemorySyncClient(api_key="...",base_url="https://api.memorysync.io",project_id="...",end_user_id="usr_7f3a9c2e",) as client:response = client.query("What should I remember?", k=3)