Python SDK
The synapse-layer package on PyPI provides a synchronous client for storing and recalling encrypted memories. One class, three methods, zero boilerplate.
On this page
Installation
pip install synapse-layerRequires Python 3.10+. The package depends on cryptography≥48.0.1, pydantic≥2.4.0, and httpx≥0.27.0.
For framework integrations, install optional extras:
# LangChain integration
pip install synapse-layer[langchain]Quick Start
from synapse_layer import Synapse
client = Synapse(api_key="sk_connect_your_token")
# Store a memory — encrypted server-side with AES-256-GCM
client.remember("User prefers dark mode and TypeScript")
# Recall relevant memories via semantic search
results = client.recall("user preferences")
for memory in results:
print(memory["content"], memory["trust_quotient"])Note
sk_connect_* token from Forge → Dashboard → Connect.Client Reference
The Synapse class (aliased as SynapseClient) is the primary interface.
Constructor
| Parameter | Type | Description |
|---|---|---|
| api_key | str | Connect token (sk_connect_*). Also accepts token= kwarg. |
| base_url | str | Forge URL. Default: https://forge.synapselayer.org |
| agent_id | str | Agent namespace. Default: sdk-client |
| timeout | float | HTTP timeout in seconds. Default: 15.0 |
| verbose | bool | Enable debug logging. Default: False |
Methods
store(content, *, memory_type, metadata) → dict
Persist a memory. Returns memoryId, contentHash, trustQuotient.
remember(content, ...) → dict
Alias for store().
recall(query, *, top_k, mode) → list[dict]
Semantic recall. Returns list of memories with content, trust_quotient, intent, agent, timestamp.
list_memories(*, limit) → list[dict]
List recent memories. Default limit: 10.
close() → None
Release the HTTP connection pool. Also supports context manager (with Synapse(...) as client:).
Framework Integrations
Built-in adapters for popular AI frameworks:
| Framework | Import | Install |
|---|---|---|
| LangChain | from synapse_memory.integrations import SynapseChatMessageHistory | pip install synapse-layer[langchain] |
| CrewAI | from synapse_memory.integrations.crewai_memory import SynapseCrewStorage | pip install synapse-layer crewai |
| AutoGen | from synapse_memory.integrations.autogen_memory import ... | pip install synapse-layer autogen |
| LlamaIndex | from synapse_memory.integrations.llamaindex import ... | pip install synapse-layer llama-index |
| Semantic Kernel | from synapse_memory.integrations.semantic_kernel import ... | pip install synapse-layer semantic-kernel |
Error Handling
The SDK raises specific exceptions from synapse_memory.exceptions:
| Exception | When |
|---|---|
| ForgeAuthError | Invalid or expired Connect Token (HTTP 401) |
| ForgeRateLimitError | Rate limit exceeded (HTTP 429) |
| ForgeBackendError | Network error or unexpected server response |
from synapse_memory.exceptions import ForgeAuthError, ForgeRateLimitError
try:
client.remember("important decision")
except ForgeAuthError:
print("Check your Connect Token")
except ForgeRateLimitError:
print("Too many requests — back off and retry")Configuration
The SDK reads these environment variables as fallbacks:
| Variable | Purpose |
|---|---|
| SYNAPSE_TOKEN | Fallback Connect Token if not passed to constructor |
| SYNAPSE_FORGE_URL | Forge base URL (default: https://forge.synapselayer.org) |