Python SDK
The official Python client for SharedMemory.
pip install sharedmemory
Requires Python 3.8+.
Quick Start​
from sharedmemory import SharedMemory
memory = SharedMemory(
api_key="sm_live_...",
volume_id="your-project-id",
)
# Store a memory
result = memory.add("User prefers dark mode and compact layout")
# Search memories
results = memory.search("user preferences")
for source in results["sources"]:
print(source["content"], source["score"])
Configuration​
| Option | Type | Default | Description |
|---|---|---|---|
api_key | str | — | Required. API key (sm_live_..., sm_agent_..., etc.) |
base_url | str | https://api.sharedmemory.ai | API endpoint |
volume_id | str | — | Default project (volume) for all operations |
user_id | str | — | Scope memories to a specific user |
agent_id | str | — | Scope memories to a specific agent |
Methods​
Memory​
| Method | Description |
|---|---|
add(content, **opts) | Store a memory |
search(query, **opts) | Search memories |
add_many(items) | Store multiple memories in batch |
feedback(memory_id, rating, reason?) | Submit feedback on a memory |
Sessions​
| Method | Description |
|---|---|
start_session(session_id, **opts) | Start a conversation session |
end_session(session_id, auto_summarize?) | End session with optional summarization |
Graph​
| Method | Description |
|---|---|
get_entity(name) | Get entity details and relationships |
get_graph() | Retrieve the full knowledge graph |
Context​
| Method | Description |
|---|---|
assemble_context(template_id?) | Assemble optimized context for LLM prompting |
Entity Scoping​
Scope memories to specific users, agents, or sessions:
memory = SharedMemory(
api_key="sm_live_...",
volume_id="vol-uuid",
user_id="user-123",
agent_id="chatbot-1",
)
# All operations are automatically scoped
memory.add("User asked about pricing", session_id="sess-abc")
results = memory.search("pricing", session_id="sess-abc")
Advanced Search​
# With reranking
results = memory.search(
"project deadlines",
rerank=True,
rerank_method="llm",
include_context=True,
)
# With metadata filters
results = memory.search("preferences", filters={
"AND": [
{"field": "memory_class", "op": "eq", "value": "preference"},
{"field": "score", "op": "gte", "value": 0.5},
]
})
Async Client​
For async/await usage:
from sharedmemory import AsyncSharedMemory
memory = AsyncSharedMemory(
api_key="sm_live_...",
volume_id="your-project-id",
)
result = await memory.add("User prefers dark mode")
results = await memory.search("preferences")
PyPI​
https://pypi.org/project/sharedmemory/
License​
MIT