Python SDK for interacting with the Memory server with multi-tenant scope isolation.
Project description
🧠 virstack-memory
A professional Python SDK for the Memory server with strict multi-tenant isolation.
virstack-memory is a fluent, async-first Python client designed specifically for integrating AI agents with the Memory knowledge graph server. It ensures robust data isolation across complex enterprise hierarchies (Projects → Workspaces → Agents → Customers).
✨ Features
- ⛓️ Fluent Scope Chaining: Intuitive builder pattern
client.project("A").workspace("B").agent("C") - 🏢 Multi-Tenant Isolation: Automatically generates isolated database buckets (e.g.,
proj_1_ws_A_agt_X_cust_999). - 🔎 Cascading Search: Retrieve combined context across all ancestor scopes in a single query.
- 🛡️ Type Safety: Built with Pydantic v2 DTOs that strictly match the Memory FastAPI schema.
- ⚡ Async-First: Powered by
httpx.AsyncClientfor high-concurrency LLM workflows. - 🚦 Structured Errors: Clean exception hierarchy for connection issues, API errors, and validations.
📦 Installation
Install via pip:
pip install virstack-memory
Or using uv:
uv add virstack-memory
🚀 Getting Started
Looking for the full manual? Check out the Comprehensive Documentation.
Initialize the client, build your scope, and start interacting with the graph.
import asyncio
from virstack_memory import MemoryClient, Message
async def main():
# 1. Initialize the async client
async with MemoryClient("http://localhost:8000") as client:
# 2. Build the exact isolation scope for this interaction
memory = (
client
.project("virstack_prod")
.workspace("acme_corp")
.agent("support_bot")
.customer("cust_123")
)
# 3. Fetch cascaded context (Searches Project + Workspace + Agent + Customer)
facts = await memory.search(
query="What are the customer's previous issues?",
include_parents=True,
)
for fact in facts:
print(f"💡 {fact.fact}")
# 4. Save the conversation transcript
await memory.add_messages([
Message(role_type="user", content="I need a refund."),
Message(role_type="assistant", content="I'll process that right away."),
])
# 5. GDPR Compliance: Delete just this specific customer's data
await memory.delete()
if __name__ == "__main__":
asyncio.run(main())
🏗️ How Scope Isolation Works
The SDK constructs hierarchical group_id strings that map to isolated buckets within the Neo4j backend graph.
scope = client.project("1").workspace("A").agent("X").customer("999")
| Property | Generated Value |
|---|---|
active_group_id |
proj_1_ws_A_agt_X_cust_999 |
cascading_group_ids |
["proj_1", "proj_1_ws_A", "proj_1_ws_A_agt_X", "proj_1_ws_A_agt_X_cust_999"] |
[!TIP] Cascading Search Magic: When executing
search(..., include_parents=True), the SDK sends allcascading_group_idsto the server. This allows your agent to simultaneously retrieve global policies (Project level), tenant-specific rules (Workspace level), agent personas (Agent level), and conversation history (Customer level)—all isolated but accessible when needed.
📚 API Reference
MemoryClient
The root HTTP client and entry point for building scopes.
| Method | Endpoint | Description |
|---|---|---|
healthcheck() |
GET /healthcheck |
Checks if the Memory server is reachable. |
clear() |
POST /clear |
⚠️ DANGER: Wipes ALL graph data globally. |
project(id) |
— | Starts a new scope chain. |
MemoryScope
The scoped execution context.
| Method | Endpoint | Description |
|---|---|---|
workspace(id) |
— | Narrows scope to a Workspace. |
agent(id) |
— | Narrows scope to an Agent. |
customer(id) |
— | Narrows scope to a Customer. |
add_messages(...) |
POST /messages |
Queues a conversation transcript for ingestion. |
add_entity_node(...) |
POST /entity-node |
Manually creates a graph entity node. |
search(...) |
POST /search |
Retrieves facts matching a natural language query. |
get_memory(...) |
POST /get-memory |
Generates context directly from recent messages. |
get_episodes(...) |
GET /episodes/{id} |
Fetches recent conversation episodes. |
delete() |
DELETE /group/{id} |
Permanently deletes all data within this exact scope. |
🛠️ Development Setup
We use uv for dependency management and make for developer workflows.
# Install all dependencies (including dev)
make install
# Run the complete verification suite (format, lint, typecheck, tests)
make check
# Run tests
make test-unit
make test-integration
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 virstack_memory-0.1.1.tar.gz.
File metadata
- Download URL: virstack_memory-0.1.1.tar.gz
- Upload date:
- Size: 42.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07d807b17519081f98d9b924fb4e3133b241986628356e1009cecaa1318d1839
|
|
| MD5 |
173814cbfdf3dc5f191c7aaa17679c07
|
|
| BLAKE2b-256 |
884fba3fc429359cd59efd5f438aba5fde4aae631876805f07b46118af9b5fd8
|
File details
Details for the file virstack_memory-0.1.1-py3-none-any.whl.
File metadata
- Download URL: virstack_memory-0.1.1-py3-none-any.whl
- Upload date:
- Size: 11.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7d38fc1c76a3b9bc65e3eb454e7a60722883a20299006bd0e7a9d9e8f5c7e83
|
|
| MD5 |
ce3ef953df4ac57d1a61fd5e78a16c3f
|
|
| BLAKE2b-256 |
b72616a7ec74dc4a79ea4c95f9b903f1e070238e8de1bf08ce0f4372b44f7461
|