SDKs · Python
Python Memory Client
Build against the 35 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) | 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_import(file, ...) | dict | Upload a payload and start an import job. |
get_import(job_id) | dict | Poll one job’s status and counters. |
list_imports(...) | dict | Recent import jobs, newest first. |
cancel_import(job_id) | dict | Ask the worker to stop between batches. |
create_relation(from_memory_id, ...) | Relation | Create a documented relationship between records. |
add_turn(tenant_id=..., user_id=..., ...) | dict | Store one conversational turn verbatim (episodic ingestion). |
recall(tenant_id=..., user_id=..., prompt=..., k=None) | dict | Build a prompt-ready context block for an LLM call. |
list_memories(tenant_id=..., user_id=..., ...) | dict | Page through a specific end user’s memories. |
retrieve(query, ...) | QueryResponse | Alias of query against /memory/retrieve — identical semantics. |
search_routed(query, route=None, ...) | dict | Route a question to the best knowledge source and answer from it. |
synthesize(query=None, memory_ids=None, ...) | dict | Compose an answer across several memories, with citations. |
upload(file, filename=..., ...) | AddResult | Ingest a document and store the memories extracted from its text. |
batch_update(items) | BatchUpdateResponse | Apply up to 100 metadata edits in one request. |
refresh() | dict | Re-embed this end user’s memories; returns immediately (202). |
status(memory_id) | dict | Async ingestion status for one memory. |
history(memory_id, limit=100, offset=0) | HistoryResponse | Recorded changes to one memory, oldest first. |
feedback(memory_id, signal, comment=None) | FeedbackResponse | Tell MemorySync whether a memory was useful; tunes ranking. |
graph(limit=None, memory_id=None, depth=None) | dict | Nodes and typed edges for this end user’s memory graph. |
clusters(limit=None) | dict | Semantic clusters over this end user’s memories. |
decisions(limit=None) | dict | Contradictions and open decisions detected across memories. |
resolve_decision(decision_id=None, ...) | dict | Record which side of a contradiction wins. |
intelligence(limit=None, scope=None, ...) | dict | The intelligence report: themes, entities, patterns. |
knowledge_stats() | dict | Counts and coverage for the knowledge base. |
get_ontology() | Ontology | The memory vocabulary in effect for this organization. |
update_ontology(content_types=None, relation_types=None) | Ontology | Replace this organization’s additions to the vocabulary. |
purge_user() | always raises | Guard method: account erasure lives in the Control Plane SDK, never here. |
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)
Reference and safety
Was this page helpful?