Official Python SDK for the Switchy AI memory, chat, and MCP server API
Project description
switchy-sdk
Official Python SDK for the Switchy AI memory, knowledge-graph, and multi-model chat API.
Install
pip install switchy-sdk
Quick start
from switchy import Switchy
client = Switchy(api_key="switchy_...")
response = client.chat.complete(
model="anthropic/claude-sonnet-4",
message="Summarise my recent project notes",
memory={"enabled": True, "extractMemories": True},
)
print(response["message"]["content"])
MCP server (v0.2.0)
Switchy is also an MCP server. Use McpClient to call its tools from your own
Python code (the same surface Claude Desktop and Cursor talk to).
from switchy import McpClient
mcp = McpClient(api_key="sk_live_...")
# Org-scoped reads + writes — no actor needed.
result = mcp.search_memory(query="launch readiness")
for m in result["memories"]:
print(m["content"])
mcp.add_memory(content="We picked Ably for realtime in April 2026.", visibility="ORG")
# Acting on behalf of a specific human (required for PRIVATE memory access
# and post_message). The key must carry the act_on_behalf scope.
as_alice = mcp.act_as_user("user_abc123")
as_alice.post_message(
session_id="cmo5...",
content="Posting from a script — @claude please draft a reply.",
)
There's also an AsyncMcpClient with the same surface for asyncio callers.
Errors
| Class | When |
|---|---|
McpAuthError |
401 / 403 — missing key, wrong scope, actor not in org |
McpNotFoundError |
404 — resource doesn't exist OR isn't visible to the caller |
McpInvalidParamsError |
400 — params didn't match the tool's schema |
McpRateLimitError |
429 — retry_after_ms, cap, kind available on the error |
McpError |
catch-all base class |
Key minting + docs
Mint a key at https://switchy.build/settings#api-keys (click Mint MCP key). Full install snippets for Claude Desktop / Cursor / generic HTTP live at https://switchy.build/docs/mcp. The OpenAPI spec is at https://switchy.build/api/mcp/openapi.json.
Streaming
for chunk in client.chat.stream(
model="openai/gpt-5",
message="Write a haiku about memory",
):
if chunk.get("type") == "token":
print(chunk.get("content", ""), end="", flush=True)
Async
import asyncio
from switchy import AsyncSwitchy
async def main():
async with AsyncSwitchy(api_key="switchy_...") as client:
res = await client.chat.complete(
model="anthropic/claude-sonnet-4",
message="Hello",
)
print(res["message"]["content"])
asyncio.run(main())
Memory
# Create a namespace
client.namespaces.create(name="my-project")
# Store a memory frame
client.memory.create_frame(
"my-project",
content="User prefers dark mode and TypeScript",
metadata={"source": "onboarding"},
)
# Contextual retrieval
relevant = client.memory.context("my-project", query="user preferences", limit=5)
Knowledge graph
client.knowledge_graph.create_entity(
"my-project", name="AuthService", type="service"
)
client.knowledge_graph.create_relation(
"my-project", source="AuthService", target="User", type="authenticates"
)
Error handling
from switchy import Switchy, SwitchyError, RateLimitError
try:
client.chat.complete(model="openai/gpt-5", message="hi")
except RateLimitError as e:
print(f"Rate limited, retry in {e.retry_after}s (limit={e.limit})")
except SwitchyError as e:
print(f"API error: {e.code} — {e}")
API reference
chat.complete(...)— single-turn completionchat.stream(...)— SSE streaming iteratormodels.list(featured=True)— list available models (350+)namespaces.{create,list,get,update,delete}— memory namespace managementmemory.{create_frame,list_frames,context,semantic,search,bridge,consolidate}— memory operationsknowledge_graph.{create_entity,create_relation,query}— graph operationssessions.{create,list,get}— session management
Full OpenAPI spec: https://switchy.build/api/v1/openapi.json
License
MIT
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 switchy_sdk-0.2.0.tar.gz.
File metadata
- Download URL: switchy_sdk-0.2.0.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9521a3773e495e852e04e927a4fbdcf313db97cdd14ded2e21e8209edf6a6b93
|
|
| MD5 |
a77bf4372f87a3d5d0dc34f59ebde77d
|
|
| BLAKE2b-256 |
e0c3266e751fd5a4f964a3c927176006bb81675fdcb8d6000b67d8e6d7fcd5e5
|
File details
Details for the file switchy_sdk-0.2.0-py3-none-any.whl.
File metadata
- Download URL: switchy_sdk-0.2.0-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f61d99258e09f98340d6117099cfc3eae71068e82d625b0cb3e4144bf1ce8fa5
|
|
| MD5 |
515803bd77d1226bc7baa1442f06ee42
|
|
| BLAKE2b-256 |
b8f0a1724441286969caaa3120d7449c5a9c47926a19108a4e6d2bb33e5d8816
|