Skip to main content

switchy-sdk

Official Python SDK for Switchy. Switchy / AsyncSwitchy are clients for the Switchy v1 API, which gives you team memory over HTTP and authenticates with an org API key (sk_live_…). McpClient / AsyncMcpClient are clients for Switchy's MCP server and authenticate with an MCP key.

Upgrading from 0.3.x? 0.3.x called Switchy's session-only web-app API, so with an API key every resource call raised AuthError (401). 0.4.0 targets the v1 API. See Migrating from 0.3.

Install

pip install switchy-sdk

Python 3.9+.

Get an API key

An owner or admin of your org mints an sk_live_… key in Settings → API keys. The key is shown once. It is scoped to that org and acts as the user who minted it. (McpClient uses a different key; see MCP client.)

Hello world (sync)

from switchy import Switchy

client = Switchy(api_key="sk_live_...")

memory = client.memory.create(
    content="Deploys go out on Thursdays.",
    type="FACT",
    visibility="ORG",
)

hits = client.memory.search(query="deploys")
print(hits[0].content, hits[0].relevance)

page = client.memory.list(limit=20)
print(page.total, [m.content for m in page.memories])

client.memory.delete(memory.id)

Hello world (async)

import asyncio
from switchy import AsyncSwitchy

async def main():
    async with AsyncSwitchy(api_key="sk_live_...") as client:
        hits = await client.memory.search(query="deploys")
        print([h.content for h in hits])

asyncio.run(main())

What you can do

Switchy and AsyncSwitchy expose the same methods. The async ones are awaitable.

client.memory.list(page=..., limit=..., type=..., min_importance=...)                 # GET    /memory        -> MemoryPage
client.memory.create(content=..., type=..., visibility=..., project_id=..., tags=...)  # POST   /memory        -> CreatedMemory
client.memory.search(query=..., type=..., limit=..., min_importance=...)              # POST   /memory/search -> List[MemorySearchHit]
client.memory.delete(memory_id)                                                       # DELETE /memory?id=    -> DeletedMemory
  • Visibility: "PRIVATE" (only you, and the default), "PROJECT" (members of one Project, which needs project_id), or "ORG" (everyone in the org). Reads only return what the key's user is allowed to see.
  • type is required on create: "FACT", "CONTEXT", "INSTRUCTION", "PREFERENCE", "CONVERSATION", "SUMMARY" or "INSIGHT".
  • search returns memories whose content contains query, case-insensitively, best match first. It is a text match, not a semantic search.
  • list is ordered by importance, then newest first. The server ranks at most 100 visible memories, so total, stats and paging stop there.
  • Duplicates: writing content that already exists in the org raises ConflictError with code == "DUPLICATE_CONTENT", and details["id"] holds the existing memory's id.

Return values are pydantic v2 models from switchy.models: Memory, MemoryPage, MemoryStats, CreatedMemory, MemorySearchHit, DeletedMemory. Attributes are snake_case (created_at, has_next_page, project_id). Call .model_dump() if you need a dict.

For other v1 endpoints (spec at /api/v1/openapi.json), use request(). It handles the auth header, the envelope and errors:

data = client.request("GET", "/namespaces")

MCP client

Switchy is also an MCP server. You can call its tools over JSON-RPC from your own code. Sync and async variants are available:

from switchy import McpClient, AsyncMcpClient

mcp = McpClient(api_key="switchy_...")
tools = mcp.tools()
result = mcp.search_memory(query="launch readiness")

McpClient takes the site origin as base_url (default https://switchy.build) and posts to {base_url}/mcp/rpc. Do not pass it the REST base URL (…/api/v1).

Tool calls need a key with the matching mcp:* scopes. Click Mint MCP key in Settings → API keys to get one. An sk_live_ org key can initialize() and list tools, but it has no mcp:* scopes, so tool calls raise McpAuthError (403, SCOPE_MISSING). See /docs/mcp for the tool list and scopes.

Errors

Every method returns a model or raises a typed error, chosen by HTTP status. The server's own code is on err.code:

Class HTTP Typical code
ValidationError 400 VALIDATION_ERROR, plus issues
AuthError 401 AUTH_ERROR
ForbiddenError 403 AUTHORIZATION_ERROR, INSUFFICIENT_SCOPE, NOT_ORG_MEMBER, NOT_PROJECT_MEMBER
NotFoundError 404 NOT_FOUND
ConflictError 409 DUPLICATE_CONTENT
RateLimitError 429 RATE_LIMIT_EXCEEDED, plus retry_after in seconds, limit, reset_at
ServerError 5xx INTERNAL_ERROR

An AuthError message tells you what to check: whether the key was revoked, whether it is an sk_live_ org key, and whether base_url points at the v1 API. It also names the base URL the client used.

from switchy import AuthError, ConflictError, RateLimitError

try:
    client.memory.create(content=content, type="FACT")
except ConflictError as e:
    print("already stored as", e.details["id"])
except RateLimitError as e:
    print(f"retry in {e.retry_after}s")
except AuthError as e:
    print(e)

Rate limits and retries

v1 requests are rate limited per plan, per minute and per day. The SDK retries a 429 up to max_retries times (default 2), but only when Retry-After is 60 seconds or less. A longer wait, such as a daily cap, raises RateLimitError right away so your process doesn't sleep for hours.

Migrating from 0.3

0.3.x called https://switchy.build/api, the API behind the Switchy web app. It authenticates with a browser session, not an API key, so every 0.3.x resource call raised AuthError. 0.4.0 calls the v1 API instead.

0.3.x 0.4.0
client.memory.create(content=..., visibility="SPACE", space_id=...) client.memory.create(content=..., type="FACT", visibility="PROJECT", project_id=...)
client.memory.search(query=..., space_id=...) → hits with .memory, .score client.memory.search(query=...) → MemorySearchHit with .content, .relevance
client.memory.list(visibility=..., space_id=..., limit=...) → List[Memory] client.memory.list(page=..., limit=..., type=..., min_importance=...) → MemoryPage
client.memory.delete(memory_id) → None client.memory.delete(memory_id) → DeletedMemory
client.spaces, sessions, messages, members, invitations Removed. Use the web app, or McpClient (list_spaces, list_sessions, get_session_transcript, post_message)
client.billing, client.mcp, client.keys Removed. Manage billing, MCP servers and keys in the web app
idempotency_key= Removed. No route implemented it. Duplicate memories are rejected by content

The full list is in CHANGELOG.md.

Configuration reference

Switchy(
    api_key="sk_live_...",                     # required
    base_url="https://switchy.build/api/v1",   # default
    timeout=60.0,                              # seconds
    max_retries=2,                             # 429 retries (Retry-After <= 60s)
    client=None,                               # custom httpx.Client (tests / shared pool)
)

License

MIT

Metadata

Release files for switchy-sdk 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for switchy-sdk 0.4.0
File Size Uploaded Provenance Actions
switchy_sdk-0.4.0.tar.gz 19.2 kB With provenance Details for switchy_sdk-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for switchy-sdk 0.4.0
File Interpreter ABI Platform Actions
switchy_sdk-0.4.0-py3-none-any.whl Python 3 none any Details for switchy_sdk-0.4.0-py3-none-any.whl

Total release size: 34.1 kB

Release files / switchy_sdk-0.4.0.tar.gz

Download URL switchy_sdk-0.4.0.tar.gz
Size 19.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b410ff5b374e43e313fbe346d93739a23b12896f3198b4837c7e3fcee21493eb
BLAKE2b-256 checksum
How to use checksums
08d5dd5b014043a5d5e73b13019107119e6ee06214945925f3c6b57310a64c18
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.

Transparency log

Release files / switchy_sdk-0.4.0-py3-none-any.whl

Download URL switchy_sdk-0.4.0-py3-none-any.whl
Size 14.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e3bdba223c126122bb1f165a88742c60516f129ab778befb6e9649dfaa1060be
BLAKE2b-256 checksum
How to use checksums
cb5e3d4def6f935ad04edcc859c16e9b02375ee92a9f3b08981789b4977a7d8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.

Transparency log

Security for switchy-sdk 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for switchy_sdk-0.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page