Official Python SDK for Switchy — the shared AI workspace for small teams.
Project description
switchy-sdk
Official Python SDK for Switchy — the shared AI workspace for small teams.
Install
pip install switchy-sdk
Hello world (sync)
from switchy import Switchy
client = Switchy(api_key="sk_live_...")
spaces = client.spaces.list()
space = spaces.projects[0]
client.memory.create(
content="Launching the new pricing page on May 15.",
visibility="SPACE",
space_id=space.id,
)
hits = client.memory.search(query="when do we launch?")
print(hits[0].memory.content)
Hello world (async)
import asyncio
from switchy import AsyncSwitchy
async def main():
async with AsyncSwitchy(api_key="sk_live_...") as client:
spaces = await client.spaces.list()
await client.messages.send(
spaces.projects[0].slug,
"sess_123",
body="@claude what should we ship first?",
)
asyncio.run(main())
What you can do
The SDK mirrors the v2 REST API one-to-one. Both Switchy (sync) and AsyncSwitchy (async) expose the same namespaces; methods either return models or raise typed errors.
client.spaces.list(page=1, limit=20)
client.spaces.get(space_id)
client.spaces.create(name=..., description=..., tags=..., idempotency_key=...)
client.sessions.list(space_slug)
client.sessions.create(space_slug, name=..., participant_user_ids=..., default_agent=...)
client.sessions.get(space_slug, session_id)
client.sessions.update(space_slug, session_id, title=..., model=...)
client.sessions.archive(space_slug, session_id)
client.messages.list(space_slug, session_id, before=..., limit=...)
client.messages.send(space_slug, session_id, body=..., parent_message_id=...)
client.messages.react(space_slug, message_id, "👍")
client.memory.list(visibility=..., space_id=..., limit=...)
client.memory.create(content=..., visibility=..., space_id=..., tags=..., source_url=...)
client.memory.search(query=..., space_id=..., limit=...)
client.memory.delete(memory_id)
client.members.list(org_id)
client.members.update_role(org_id, user_id, "ADMIN")
client.members.remove(org_id, user_id)
client.invitations.list(org_id)
client.invitations.create(org_id, email=..., role="MEMBER")
client.invitations.accept(token)
client.billing.credits()
client.billing.checkout(plan="team", interval="annual")
client.billing.portal(return_url=...)
client.billing.topup(pack="medium") # or topup(credits=1000)
client.mcp.list()
client.mcp.create(display_name=..., mention_slug=..., endpoint_url=..., auth_type=..., secret=...)
client.mcp.delete(server_id)
client.mcp.test(server_id)
client.keys.list()
client.keys.create(name=..., scopes=[...])
All return values are pydantic v2 models (Space, Session, Message, Memory, etc.) defined in switchy.models.
MCP client
Switchy is also an MCP server. From any MCP-capable client (Claude Desktop, Cursor, your own code) you can call Switchy's tools over JSON-RPC. Sync + async variants:
from switchy import McpClient, AsyncMcpClient
mcp = McpClient(api_key="sk_live_...")
result = mcp.search_memory(query="launch readiness")
# act on behalf of a specific human (required for PRIVATE memory + post_message)
as_alice = mcp.act_as_user("user_abc")
as_alice.post_message(session_id="sess_123", content="Just shipped the migration guide.")
See /docs/mcp for the full tool list.
Errors
Every method either returns a model or raises a typed error you can catch with except:
from switchy import Switchy, ValidationError, ForbiddenError, RateLimitError
client = Switchy(api_key="sk_live_...")
try:
client.spaces.create(name="")
except ValidationError as e:
print(e.issues) # zod issue list, e.g. [{"path": ["name"], "message": "required"}]
except ForbiddenError:
print("not allowed")
except RateLimitError as e:
print(f"retry in {e.retry_after}s")
The full error table — codes, HTTP status, when each fires — is at /docs/api/overview.
Idempotency
Every create method accepts idempotency_key. If you retry the same call with the same key within 24 hours, the server replays the original response instead of creating a duplicate.
import uuid
key = str(uuid.uuid4())
client.messages.send(slug, sess_id, body="hi", idempotency_key=key)
Migrating from v0.2
v0.3 is the team-workspace SDK. The shape changed because the product changed.
| v0.2 | v0.3 |
|---|---|
client.chat.complete(model=..., message=...) |
client.messages.send(slug, sess_id, body="@model message") |
client.chat.stream(...) |
Use realtime websocket via Ably (planned in 0.4) for live AGENT replies. |
client.namespaces.create(name=...) |
client.spaces.create(name=...) |
client.namespaces.list() |
client.spaces.list().projects |
client.memory.create_frame(ns, ...) |
client.memory.create(content=..., visibility=..., space_id=...) |
client.memory.search(query=..., namespaces=[...]) |
client.memory.search(query=..., space_id=...) |
client.sessions.create(namespace=...) |
client.sessions.create(space_slug, name=...) |
client.knowledge_graph.* |
Removed. KG is internal in v2; use semantic memory search. |
client.videos.* |
Removed. Re-shipping under /v1/videos later. |
Big-picture changes:
- Org context is implicit. Mint a key inside the org you want to talk to; the SDK doesn't need an
org_idarg on most calls. - Visibility is required on memory writes.
"PRIVATE"(only you),"SPACE"(Space members),"ORG"(everyone in the org). - The base URL changed from
…/api/v1to…/api. The SDK defaults; passbase_urlif you target staging. - Errors are typed. The legacy
RateLimitErrorstill works (now also exposes the v2request_id); other exceptions split intoAuthError,ForbiddenError,NotFoundError,ValidationError,ConflictError,ServerError. - Models are pydantic v2. v0.2 returned dicts; v0.3 returns typed models. If you need a dict, call
.model_dump(). - Async surface is full parity.
AsyncSwitchyexposes the same namespaces and methods, justawait-able.
If you minted a key under one org and used it in another org by accident in v0.2 — that's no longer possible. Keys lock to their minting org.
Configuration reference
Switchy(
api_key="sk_live_...", # required
base_url="https://switchy.build/api", # default
timeout=60.0, # seconds
max_retries=2, # 429 retries honouring Retry-After
client=None, # custom httpx.Client (tests / shared pool)
)
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.3.0.tar.gz.
File metadata
- Download URL: switchy_sdk-0.3.0.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa9981c32ef138a2a652213c29f87017c78be7038d24d28e6f3716e4b1a8d811
|
|
| MD5 |
1c26080555c7657bd267c12282e1f88a
|
|
| BLAKE2b-256 |
26c7af551aad7be36f18d12e21245f1d999da3ad21e2a1876be11f7649decd39
|
Provenance
The following attestation bundles were made for switchy_sdk-0.3.0.tar.gz:
Publisher:
publish-sdks.yml on Switchy-AI/switchy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
switchy_sdk-0.3.0.tar.gz -
Subject digest:
fa9981c32ef138a2a652213c29f87017c78be7038d24d28e6f3716e4b1a8d811 - Sigstore transparency entry: 1340664186
- Sigstore integration time:
-
Permalink:
Switchy-AI/switchy@254e3dffd05625b0039f4e922846a2aecea951a1 -
Branch / Tag:
refs/tags/sdk-py-v0.3.0 - Owner: https://github.com/Switchy-AI
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdks.yml@254e3dffd05625b0039f4e922846a2aecea951a1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file switchy_sdk-0.3.0-py3-none-any.whl.
File metadata
- Download URL: switchy_sdk-0.3.0-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8132beada8d5f39a482cb8242130c1d20955ca46edca9c792e45d159ccadbdfa
|
|
| MD5 |
3d3af3eeefc200e3e6d72590adea007a
|
|
| BLAKE2b-256 |
107a27bd702a1cc8ad9bf06226eae8122195769a0eeeeebb93a31d4532c11ce0
|
Provenance
The following attestation bundles were made for switchy_sdk-0.3.0-py3-none-any.whl:
Publisher:
publish-sdks.yml on Switchy-AI/switchy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
switchy_sdk-0.3.0-py3-none-any.whl -
Subject digest:
8132beada8d5f39a482cb8242130c1d20955ca46edca9c792e45d159ccadbdfa - Sigstore transparency entry: 1340664197
- Sigstore integration time:
-
Permalink:
Switchy-AI/switchy@254e3dffd05625b0039f4e922846a2aecea951a1 -
Branch / Tag:
refs/tags/sdk-py-v0.3.0 - Owner: https://github.com/Switchy-AI
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdks.yml@254e3dffd05625b0039f4e922846a2aecea951a1 -
Trigger Event:
push
-
Statement type: