Python SDK
Official Python SDK for the Weavz API.
The official Python SDK provides a clean, Pythonic interface for the Weavz API.
Installation
pip install weavz-io-sdkQuick Start
from weavz_sdk import WeavzClient
client = WeavzClient(api_key="wvz_your_api_key")
# Execute an action
result = client.actions.execute(
"slack",
"send_channel_message",
workspace_id="550e8400-e29b-41d4-a716-446655440000",
integration_alias="office_slack",
input={"channel": "#general", "text": "Hello from Weavz!"},
)
print("Message sent:", result["output"])Configuration
client = WeavzClient(
api_key="wvz_your_api_key",
base_url="https://platform.weavz.io", # Default
timeout=310.0, # Request timeout in seconds
max_retries=2, # Retry count for transient failures
)| Option | Required | Default | Description |
|---|---|---|---|
api_key | Yes | — | Your API key (wvz_... prefix) |
base_url | No | https://platform.weavz.io | API base URL |
timeout | No | 310.0 | Request timeout in seconds. Covers 5 minute Code Mode and Sandbox runs plus response overhead. |
max_retries | No | 2 | Number of retries for transient failures |
Context Manager
The client supports Python's context manager protocol to automatically close the HTTP connection:
with WeavzClient(api_key="wvz_your_key") as client:
result = client.actions.execute(
"slack",
"send_channel_message",
workspace_id="550e8400-e29b-41d4-a716-446655440000",
input={
"channel": "#general",
"text": "Hello!",
},
)
# Connection automatically closedYou can also close manually:
client = WeavzClient(api_key="wvz_your_key")
try:
# ... use client ...
pass
finally:
client.close()Resources
The client exposes namespaced resources for each API area:
| Resource | Methods | Description |
|---|---|---|
client.mcp_workspaces | list, create, get, update, delete, configure_mcp, create_access_token, add_integration, update_integration | MCP Workspaces and included endpoints; workspaces remains an alias |
client.workspaces | list, create, get, update, delete, list_integrations, add_integration, update_integration, remove_integration | Workspace management |
client.connections | list, get, create, delete, resolve | Connection management |
client.actions | execute, execute_typed, action_names, input_model, validate_input | Execute integration actions and validate generated action inputs |
client.triggers | list, enable, disable, test | Trigger management |
client.mcp_servers | list, create, get, update, delete, regenerate_token, create_bearer_token, create_access_token, create_end_user_token, create_oauth_token, add_tool, update_tool, delete_tool, execute_code, get_declarations | MCP server management |
client.api_keys | list, create, delete | API key management |
client.integrations | list, list_summary, get, resolve_options, resolve_property, oauth_status | Integration metadata |
client.connect | create_token, poll, wait, get_session | Hosted connect flow |
client.end_users | create, list, get, update, delete, create_connect_token, invite | End-user identity and connect portal management |
client.partials | list, get, create, update, delete, set_default | Saved inputs and enforced fields |
client.approval_policies | list, create, get, update, delete, test | Approval rule management |
client.approvals | list, get, approve, reject, cancel, wait | Approval request inbox and decisions |
client.skills | list, search, get, create, update, delete | Optional reusable task instructions; search is metadata-only |
client.computer_sessions | create_access | Short-lived human watch or control link for an existing Computer Control session |
Skills are optional instructions; they do not execute tasks or grant app access. Computer session access issues a human viewer link for an existing session. It does not start or provision a computer. Availability depends on your account and configured Computer Control setup. See the Skills guide, Computer Control guide, and computer access API reference.
Resource Options and Defaults
The SDK method names mirror the REST resources. Use the API reference for complete option tables, defaults, and bounds:
Common Operations
Managing Workspaces
# List workspaces
result = client.workspaces.list()
for ws in result["workspaces"]:
print(ws["name"])
# Create a workspace
result = client.workspaces.create(name="My Workspace", slug="my-workspace")
workspace_id = result["workspace"]["id"]
# Delete a workspace
client.workspaces.delete(workspace_id)Tenant Configuration APIs
Use org-wide API keys for control-plane setup when you are building your own SaaS on top of Weavz.
workspace = client.workspaces.create(name="Production", slug="production")["workspace"]
client.workspaces.add_integration(
workspace["id"],
integration_name="slack",
integration_alias="customer_slack",
connection_strategy="per_user",
)Managing Connections
# Create an API key connection
result = client.connections.create(
type="SECRET_TEXT",
integration_name="openai",
external_id="tenant_123_openai",
display_name="OpenAI Key",
secret_text="sk-...",
)
# Resolve a connection
resolved = client.connections.resolve(
integration_name="openai",
workspace_id="550e8400-e29b-41d4-a716-446655440000",
external_id="tenant_123_openai",
)
# Delete a connection
client.connections.delete(result["connection"]["id"])Executing Actions
result = client.actions.execute(
"github",
"create_issue",
workspace_id="550e8400-e29b-41d4-a716-446655440000",
integration_alias="github_prod",
input={
"repository": "my-org/my-repo",
"title": "Bug Report",
"body": "Something went wrong",
"labels": "bug",
},
)
print("Issue created:", result["output"])MCP Workspaces and Private Access
workspace_id = "550e8400-e29b-41d4-a716-446655440000"
# Add built-ins to the workspace once. MCP servers sync workspace integrations automatically.
client.workspaces.add_integration(
workspace_id,
integration_name="storage",
integration_alias="files",
settings={"persistence": {"scope": "workspace"}},
)
# Read the included endpoint; no separate server creation is needed.
workspace = client.mcp_workspaces.get(workspace_id)["workspace"]
server_id = workspace["mcpServer"]["id"]
# Issue private MCP access for an existing external end user.
access = client.mcp_workspaces.create_access_token(
workspace_id, end_user_id="user_123", expires_in=3600,
)
# Deliver access["accessToken"] and access["mcpEndpoint"] privately to that user's agent.
# Run Code Mode from your own harness
run = client.mcp_servers.execute_code(
server_id,
"""
return await weavz.files.write_file({ path: "summary.json", content: JSON.stringify({ status: "ready" }) })
""",
)
# If an approval rule pauses the run, approve it and fetch the stored result.
approved_run = client.mcp_servers.execute_code(
server_id,
approval_id="apr_9b36d3f761d84bb2b6f9a0c4b9d1f7e0",
wait_for_approval_seconds=30,
)
# Use Tool Mode when you want a small explicit surface instead of Code Mode.
client.workspaces.add_integration(
workspace_id,
integration_name="slack",
integration_alias="office_slack",
enabled_actions=["send_channel_message"],
)
tool_server = client.mcp_workspaces.configure_mcp(
workspace_id,
name="Focused Slack Tools",
mode="TOOLS",
auth_mode="oauth",
)["server"]New MCP Workspaces use Tool Mode and OAuth by default. Switch the endpoint to Code Mode before using the Code Mode examples below. Workspace access tokens work with the endpoint's current authentication mode; send the returned accessToken as Authorization: Bearer to the MCP URL. The older server-specific bearer APIs remain available for explicit bearer-enabled configurations. Shared static bearer credentials are an advanced service option and are never a substitute for individual end-user access.
Code Mode is the default recommendation for broad agent workspaces. It exposes weavz_search, weavz_read_api, and weavz_execute, while get_declarations() returns full TypeScript declarations with JSDoc and return types. If code passes the wrong input shape, execute_code() returns a tool error with validation details instead of a generic failure. Programmatic Code Mode responses include structuredContent.timings for execution and per-action latency. For Agent Browser workflows, batch several browser actions inside one Code Mode script instead of calling execute_code() once per click or screenshot. Use Tool Mode for small explicit tool surfaces.
Managing Triggers
# Enable a trigger
result = client.triggers.enable(
integration_name="github",
trigger_name="new_push",
workspace_id="550e8400-e29b-41d4-a716-446655440000",
callback_url="https://yourapp.com/webhooks/github",
integration_alias="github_prod",
)
trigger_id = result["triggerSource"]["id"]
# List active triggers
result = client.triggers.list()
for trigger in result["triggers"]:
print(f"{trigger['integrationName']}.{trigger['triggerName']}")
# Disable a trigger
client.triggers.disable(trigger_id)Managing Input Partials
# Create a partial (saved parameter preset)
result = client.partials.create(
name="Default Slack Channel",
workspace_id="550e8400-e29b-41d4-a716-446655440000",
integration_name="slack",
integration_alias="office_slack",
action_name="send_channel_message",
values={"channel": "#general"},
enforced_keys=["channel"],
)
partial = result["partial"]
# List partials for a workspace
result = client.partials.list(workspace_id="550e8400-e29b-41d4-a716-446655440000")
# Set as default for this action scope
client.partials.set_default(partial["id"], is_default=True)
# Use partial with action execution
result = client.actions.execute(
"slack",
"send_channel_message",
workspace_id="550e8400-e29b-41d4-a716-446655440000",
integration_alias="office_slack",
partial_ids=[partial["id"]],
input={"text": "Hello!"}, # channel comes from the partial
)
# Delete a partial
client.partials.delete(partial["id"])Hosted Connect Flow
Use the hosted connect page to create OAuth2 connections. Create a token, open the connect page, and poll for the result:
# Step 1: Create a connect token
result = client.connect.create_token(
integration_name="google-sheets",
connection_name="Google Sheets",
external_id="tenant_123_gsheets",
workspace_id="550e8400-e29b-41d4-a716-446655440000",
)
token = result["token"]
connect_url = result["connectUrl"]
# result also contains: expiresAt
# Step 2: Open connect_url in a browser popup to complete authorization
status = client.connect.wait(token)
if status["status"] == "COMPLETED":
print("Connection created:", status["connectionId"])Error Handling
All API errors raise WeavzError with structured error information:
from weavz_sdk import WeavzClient, WeavzError
client = WeavzClient(api_key="wvz_your_key")
try:
client.actions.execute(
"slack", "send_channel_message",
workspace_id="550e8400-e29b-41d4-a716-446655440000",
input={"channel": "invalid", "text": "Hello!"},
)
except WeavzError as e:
print(f"Message: {e}") # Human-readable error message
print(f"Code: {e.code}") # Machine-readable code (e.g., "ACTION_FAILED")
print(f"Status: {e.status}") # HTTP status code (e.g., 400)
print(f"Details: {e.details}") # Additional details (if available)Common Error Codes
| Code | Description |
|---|---|
VALIDATION_ERROR | Invalid request parameters |
ACTION_FAILED | Action execution failed |
CONNECTION_REQUIRED | Action needs a connection |
CONNECTION_NOT_FOUND | Connection doesn't exist |
INTEGRATION_NOT_FOUND | Invalid integration name |
QUOTA_EXCEEDED | Monthly usage limit reached |
RATE_LIMITED | Too many requests |
Type Hints
The Python SDK includes type hints for all resource methods and typed models for shared objects. Generated Pydantic models cover integration action inputs, so Python callers can validate known actions before sending a request.
Key Types
from weavz_sdk import WeavzClient, WeavzError
from weavz_sdk.models import (
InputPartial,
WorkspaceIntegration,
)| Type | Description |
|---|---|
WeavzClient | Main client class with all resource methods |
WeavzError | Exception string from str(error), plus code, status, and details |
InputPartial | Partial preset with values, enforced_keys, is_default |
WorkspaceIntegration | Integration instance on a workspace with alias and connection strategy |
Integration Input Types
The SDK ships with generated Pydantic models and lookup helpers for supported integration action inputs:
from weavz_sdk.integrations import (
INTEGRATION_ACTIONS,
# Slack
SlackSendChannelMessageInput,
SlackSendDirectMessageInput,
# GitHub
GithubCreateIssueInput,
GithubCreatePullRequestInput,
# Google Sheets
GoogleSheetsInsertRowInput,
GoogleSheetsReadRowsInput,
# ... all integrations follow the same pattern
get_action_input_model,
get_action_names,
validate_action_input,
)
print(INTEGRATION_ACTIONS["slack"])
# Validated input with autocomplete
input_data = SlackSendChannelMessageInput(
channel="#general",
text="Typed input!",
)
validated = validate_action_input(
"slack",
"send_channel_message",
input_data,
)
client.actions.execute_typed(
"slack",
"send_channel_message",
workspace_id="550e8400-e29b-41d4-a716-446655440000",
input=validated,
)The naming pattern is {IntegrationName}{ActionName}Input in PascalCase.
For generic builders, use the catalog and model helpers:
from weavz_sdk import WeavzClient
from weavz_sdk.integrations import INTEGRATION_ACTIONS, get_action_names, get_action_input_model
client = WeavzClient(api_key="wvz_your_api_key")
print(get_action_names("slack"))
print(client.actions.action_names("slack"))
print(INTEGRATION_ACTIONS["slack"])
model = get_action_input_model("slack", "send_channel_message")
if model is not None:
input_data = model.model_validate({
"channel": "#general",
"text": "Validated at runtime",
})
result = client.actions.execute_typed(
"slack",
"send_channel_message",
workspace_id="550e8400-e29b-41d4-a716-446655440000",
input=input_data,
)Use client.actions.execute() for dynamic or future integrations and client.actions.execute_typed() when you want the generated Pydantic model to validate known action input before the request is sent.
AI Framework Adapters
MCP is the primary hosted surface for giving agents access to Weavz. Framework adapters are a compatibility layer for teams that are embedding Weavz into their own agent runtime and need the same configured workspace actions in a framework-native tool format.
The adapters do not expose dashboard administration or platform internals. They transform customer-facing workspace action schemas into the shape each framework expects, then execute through client.actions.execute() with your API key. Framework packages stay optional.
import os
from weavz_sdk import (
WeavzClient,
create_mcp_server_action_tools,
to_openai_responses_tool,
to_anthropic_tool,
to_google_function_declaration,
to_google_adk_tool,
)
client = WeavzClient(api_key=os.environ["WEAVZ_API_KEY"])
tools = create_mcp_server_action_tools(client, "660e8400-e29b-41d4-a716-446655440000")
openai_tools = [to_openai_responses_tool(tool) for tool in tools]
anthropic_tools = [to_anthropic_tool(tool) for tool in tools]
google_functions = [to_google_function_declaration(tool) for tool in tools]
google_adk_tools = [to_google_adk_tool(tool) for tool in tools] # Requires google-adkFor LangChain, install langchain-core and call to_langchain_tool(tool). For Google ADK, install google-adk and call to_google_adk_tool(tool). For manual loops, use create_tool_executor() to route model tool calls back through client.actions.execute().
Python Version
The SDK requires Python 3.10 or later and depends on:
Upgrading to 0.2.0
The 0.2.0 release corrects the customer API contract, request handling, and framework adapters.
- Nullable response fields now reflect the API. Check for
nullbefore using an unassigned workspace, end user, or optional relationship. - Google function declarations use
parametersJsonSchemarather thanparameters, preserving JSON Schema arrays, numeric enums, and unions. Pass the declarations directly to a current Google client. Update code that reads the old field explicitly. - Request timeouts, cancellation, malformed responses, and finite retry delays are handled consistently. Action POST requests are not replayed after an ambiguous network failure or server error.
- MCP adapters retain their configured end-user identity, connection, defaults, and saved input rules. Conflicting bindings and duplicate tool names fail explicitly.
See the customer OpenAPI contract for current request and response shapes.
For nullable PATCH fields, an explicit None clears the value. Omitted fields remain unchanged. Typed action inputs serialize dates and other supported Pydantic values as JSON.
Returning OAuth completion to your frontend
When your backend prepares a Hosted Connect URL for a browser popup, set Origin to that frontend's exact origin. Choose it from server configuration or an allowlist. Keep your API key on the backend.
import os
from weavz_sdk import WeavzClient
connect_client = WeavzClient(
api_key=os.environ["WEAVZ_API_KEY"],
headers={"Origin": "https://app.example.com"},
)
session = connect_client.connect.create_token(
integration_name="slack",
connection_name="Customer Slack",
external_id="customer_slack",
workspace_id="550e8400-e29b-41d4-a716-446655440000",
)
# Return session["connectUrl"] to the authorized browser.Use openConnectPopup from the TypeScript SDK in your frontend, or poll the session from your backend with connect.wait().