Skip to content

Python SDK

The MemoryLayer Python SDK (memorylayer-client) provides async and sync Python clients for the MemoryLayer server. It is Apache-2.0 licensed and requires Python 3.12+.

Installation

Terminal window
pip install memorylayer-client
# Optional: route requests over an Aether mesh
pip install "memorylayer-client[aether]"

Features

  • Async and Sync — MemoryLayerClient (async context manager) and SyncMemoryLayerClient
  • Type-Safe — Complete type hints with Pydantic models
  • Memory Operations — Remember, recall (including temporal filters and token budgets), reflect, forget, decay, browse
  • Relationship Graph — Link, update, and traverse typed relationships between memories
  • Entity Registry — Resolve and merge canonical entities
  • Sessions — Working memory with TTL and commit, plus checkpoints, context packs, and context deltas for recovery after compaction
  • Chat Threads — User-owned conversation history with decomposition into memories
  • Skills, MCP Servers, Knowledgebase, RPG — Namespaced sub-APIs (client.skills, client.mcp_servers, client.kb, client.rpg)
  • On-Behalf-Of — Per-call or scoped OBO authority, with an optional Aether transport
  • Retries — Automatic backoff for idempotent requests on transient failures
  • Error Handling — Typed exception hierarchy

Quick Start

from memorylayer import MemoryLayerClient, MemoryType
async with MemoryLayerClient(
base_url="http://localhost:61001",
workspace_id="my-workspace"
) as client:
# Store a memory
memory = await client.remember(
content="User prefers Python for backend development",
type=MemoryType.SEMANTIC,
importance=0.8,
tags=["preferences", "programming"]
)
# Search memories
results = await client.recall(
query="what programming language does the user prefer?",
limit=5
)
for memory in results.memories:
print(f"{memory.content} (relevance: {memory.relevance_score})")
# Synthesize memories
reflection = await client.reflect(
query="summarize user's technology preferences"
)
print(reflection.reflection)

Configuration

client = MemoryLayerClient(
base_url="http://localhost:61001", # Server URL
api_key="your-api-key", # Optional for local dev
workspace_id="my-workspace", # Default workspace
session_id="sess_123", # Optional active session
timeout=30.0, # Request timeout in seconds
max_retries=3, # Retries for idempotent requests
)

Next Steps

Other SDKs

  • TypeScript SDK — @scitrera/memorylayer-sdk for Node.js and browsers
  • Go SDK — github.com/scitrera/memorylayer/memorylayer-sdk-go