Python SDK
wakeshift for Python 3.10 or later, on the official MCP Python SDK (mcp 2.3 or later). It has the same calls as the TypeScript and Go SDKs, in Python's style: define_event, serve_events, GuestAuth, WakeshiftSignIn, and the topic calls. Every call that reaches Wakeshift is async. During the beta it comes with your invite; it isn't on PyPI.
uv add ./wakeshift-0.1.0-py3-none-any.whlEvents
Define the events your app offers, serve them on your MCP server, and emit them when they happen. Clients that speak MCP Events, such as ChatGPT, subscribe natively; every other agent subscribes with the subscribe_events tool serve_events adds.
import os
from mcp.server.mcpserver import MCPServer
from pydantic import BaseModel
from wakeshift import GuestAuth, Wakeshift
wake = Wakeshift(os.environ["WAKESHIFT_KEY"], core=os.environ.get("WAKESHIFT_CORE"))
class Channel(BaseModel):
channel: str
class Message(BaseModel):
sender: str
text: str
message = wake.define_event(
"chat.message",
description="A new message in a channel",
args=Channel,
payload=Message,
text=lambda m, a: f"{m.sender} in #{a.channel}: {m.text}",
)
server = MCPServer("chat")
wake.serve_events(server)
# Guests: MCP clients sign in with no account, each in its own workspace.
guests = GuestAuth(wake, "https://chat.example.com/mcp")
app = guests.wrap(server.streamable_http_app())
async def on_message(channel: str, sender: str, text: str) -> None:
await message.emit({"channel": channel}, {"sender": sender, "text": text})| Call | What it does |
|---|---|
wake.define_event(name, description=, args=, payload=, text=, authorize=None, personal=False) |
Defines an event. args and payload are pydantic models or JSON Schemas; text(payload, args) is the line the agent reads first; authorize(subscriber, args) decides who may subscribe. A personal event goes to one subscriber at a time. |
await event.emit(args, payload, to=None, id=None) |
Sends one occurrence to everyone subscribed with those arguments, or, for a personal event, to the subscriber to names. |
wake.serve_events(server, user=None, agent=None) |
Serves events/list, events/subscribe and events/unsubscribe, and the tools subscribe_events, unsubscribe_events and list_subscriptions. user(ctx) is your ID for the person; by default, the guest GuestAuth signed in. agent(ctx) is the signed-in agent, for apps on Wakeshift accounts. |
await event.subscribe(ctx, args, user= or agent=, wake_args=) |
Subscribes the conversation calling one of your own tools, so a tool like "join" sets up its wakes in one step. |
await event.unsubscribe(ctx, args, user= or agent=, wake_args=) |
Ends the calling conversation's subscription with those arguments, for a tool like "unwatch". |
await event.publish_url(args, to=None) |
A URL that emits the event with those arguments: each POST's body is the payload, checked against the schema. wake.revoke_publish_url(id) turns it off. See emit from a webhook. |
await event.end(user, id) |
Ends one of a user's subscriptions by its ID. |
The tools' wording and the events/list output are the same as the TypeScript and Go SDKs', word for word.
Sign-in
GuestAuth(wake, mcp_url)signs MCP clients in as guests, with no account: an OAuth server inside your app that keeps no state.guests.wrap(app)serves it and requires a token on/mcp;guest_of(ctx)is who's calling.WakeshiftSignIn(wake, redirect_uri)is Sign in with Wakeshift for the browser:start()andawait finish(request, response).- For apps whose users sign in with Wakeshift, pass
mcp_url=toWakeshift:await wake.verify_access_token(token)checks a request's token, andawait wake.exchange(token)returns theAgentto pass asagent.wake.protected_resource()andwake.challenge()are what MCP clients need to find Wakeshift.
Topics
Topics are what events are built on. wake.call(ctx, ...) packs a tool call, and wake.subscribe, wake.publish, wake.annotate, wake.publish_url, wake.forget_user and the rest work as their TypeScript counterparts do, with snake_case names. Add SessionKey, Harness and ConversationId to a subscribe tool's parameters for the arguments Wakeshift needs from the agent.