Get started

Call From your code 02 / 07

SDKs

Python, TypeScript, Go and Rust clients for Writ Cloud and Writ Desktop.

Runs on Writ CloudWrit Desktop

Markdown Open in Claude Open in ChatGPT

Writ has four official SDKs, all open source under the MIT license. Each one has a cloud client that talks to Writ Cloud and a local client that talks to Writ Desktop on the same computer. The SDKs run what already exists: you build an API in the app, with Scribe or from your AI assistant, then your code runs it, reads its data and follows its monitors.

Install

pip install writ-agent
LanguagePackageImportNeeds
Pythonwrit-agent (PyPI)writ_agentPython 3.10+
TypeScript@usewrit/agent-sdk (npm)@usewrit/agent-sdkNode 18+
Gogithub.com/usewrit/writ-sdks/gopackage writGo 1.23+
Rustwrit-client (crates.io)writ_clientRust stable, an async runtime such as Tokio

All four are at version 1.3.0 and implement the same contract, so an example translates almost line for line between languages.

Connect to Writ Cloud

Create a key in Developers → API Keys and put it in the WRIT_API_KEY environment variable. The cloud client reads it from there; you can also pass it in code. Give the key the permissions your code needs: to run an API and wait for it, it must be able to run and read workflows.

from writ_agent import Cloud

# Reads WRIT_API_KEY from the environment.
# Or pass it: Cloud(api_key="wt_...")
cloud = Cloud()

Read a page

Turn one page into clean Markdown. Pass a persona id to read a page behind a login.

page = cloud.scrape("https://news.ycombinator.com")
print(page["title"])
print(page["markdown"][:500])

Run an API and wait

Start a run of an API by its id and wait until it finishes. If your timeout passes first, the SDK raises an error, but the run keeps going and its task id still reaches it.

task = cloud.workflows.run_and_wait(
    42,                        # the API's id
    inputs={"limit": 3},
    function_name="top_stories",  # optional: run one function
    timeout=300,               # seconds to wait; the run itself is never cancelled
)
print(task["status"])          # success | failed | cancelled
print((task.get("result_data") or {}).get("extracted_data"))

A run that fails comes back normally with status set to failed, so check it. The extracted data sits under result_data.extracted_data.

Read monitor changes

List what a monitor detected, newest first. For a continuous feed across all your monitors, use watch: it returns every change once, in the order Writ detected them, and you can resume it after a restart from the last change you processed.

changes = cloud.monitors.changes(17, limit=20)   # newest first
for c in changes:
    print(c["lastDetectedAt"], c["newContent"][:80])

# A continuous feed across all monitors, in detection order:
# for c in cloud.monitors.watch(): ...

Connect to Writ Desktop

The local client finds a running Writ Desktop by itself. It reads the app's address and token from ~/.writ/runtime.json and checks that the app answers before using it, so on the same computer there is nothing to configure. To reach Desktop on another machine, set WRIT_API_URL to its address and WRIT_TOKEN to a local wlk_ key.

from writ_agent import WritAgent, run_row_id

with WritAgent() as writ:              # finds the running Writ Desktop
    workflows = writ.workflows.list()
    run = writ.workflows.run_and_wait(
        workflows.data[0]["id"], inputs={"query": "espresso"}
    )
    print(run["status"])
    print(writ.runs.data(run_row_id(run))["data"])

Everything you run through the local client happens on your computer and costs nothing. The local client also covers monitors, automations, personas, secrets, files, datasets and local API keys. Its routes are listed on Desktop local API.

What the SDKs handle for you

  • Safe retries. Cloud calls that hit a rate limit, a timeout or a server error are retried with backoff, honoring Retry-After. Each POST carries one Idempotency-Key for all its attempts, so a retry never runs your API twice. Local calls that change something are never retried.
  • Typed errors. Running out of credits, hitting a plan limit, a rate limit or a missing key each raise their own error type, with the server's code and message.
  • One list shape. Every list comes back as a page with data, count and, when known, total, and there are helpers to walk all pages.
  • Webhook verification. A helper verifies the signature and the timestamp of a delivery Writ sends to your server.
import os
from writ_agent import verify_webhook, WritWebhookVerificationError

def is_from_writ(headers, body: bytes) -> bool:
    # body = the raw request bytes, exactly as received
    try:
        verify_webhook(headers, body, os.environ["WRIT_WEBHOOK_SECRET"])
        return True
    except WritWebhookVerificationError:
        return False

What Writ signs, and how to verify it without an SDK, is on Schedules, triggers and webhooks.

Packages for websites

Three more packages serve a different job: running your workflows from your own website, on each visitor's computer, through the Writ browser extension and Writ Desktop, with Writ Cloud as the fallback. You set this up under Developers → Publications → Use on a website.

PackageSideWhat it does
@usewrit/web (npm)Your web pageShows the setup banner, installs your workflows on the visitor's computer and calls them.
@usewrit/server (npm)Your Node serverCalls your workflows from your backend: on the visitor's computer, checked against a signed receipt, or on Writ Cloud with your API key.
usewrit (PyPI)Your Python serverThe same for Python, with a FastAPI integration.

Next