Skip to main content

statewire

The Statewire protocol for Python: a Statewire host owns one JSON state dict, streams every change to attached clients as ops, and dispatches typed commands back. Part of harness-sdk, with harness-sdk and Pinboard.

Install

uv add statewire

Extras: uv add "statewire[langgraph]", uv add "statewire[orjson]".

Use

from fastapi import FastAPI
from pinboard import Worker
from statewire import Statewire, StatewireReject, command

class Counter(Statewire):
    async def lifespan(self):
        self.state = {"count": 0}
        yield

    @command
    async def increment(self):
        if self.state["count"] >= 10:
            raise StatewireReject("the counter is full (max 10)")
        self.state["count"] += 1

worker = Worker(hosts={"/threads": Counter})
app = FastAPI()
app.include_router(worker)

Protocols and documents

Connections negotiate date ranges through Statewire-Version and Statewire-Protocol. Protocols are additive and required by default. The server selects versions in syn; WebSockets use statewire.v1.

Each protocol owns its commands and its documents, and mints statement seqs in its own lane. Ephemeral subprotocols (Statewire.Subprotocol("interest", record="ephemeral")) restart their lane on every attach and carry per-attach documents mounted from handlers via ctx.attach. Python hosts support chained compatibility adapters.

See the protocol registration and migration guide.

Docs

Lease context

client = StatewireClient.sse(url, context={"acme-chat": {"locale": "en"}})
client.set_context("acme-chat", {"locale": "de"})

Context is a full object per protocol and connection lease. The client restores its latest values on every new attachment, including a fresh hello on the same socket. Hosts validate candidates through validate_context and react through context_changed. Commands read their admission snapshot through ctx.context; later replacements do not alter queued commands. Context supports document datetime metadata, has a 64 KiB limit per entry, and consumes no command sequence numbers.

Metadata

Release files for statewire 0.24.2

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

Source distribution (sdist)

Source distribution for statewire 0.24.2
File Size Uploaded Provenance Actions
statewire-0.24.2.tar.gz 166.6 kB With provenance Details for statewire-0.24.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for statewire 0.24.2
File Interpreter ABI Platform Actions
statewire-0.24.2-py3-none-any.whl Python 3 none any Details for statewire-0.24.2-py3-none-any.whl

Total release size: 249.6 kB

Release files / statewire-0.24.2.tar.gz

Download URL statewire-0.24.2.tar.gz
Size 166.6 kB
Tags Source
SHA-256 checksum
How to use checksums
75afce2aeb051696ac703eb2f110da174a80288fc2167310d2df740d2ecb7f96
BLAKE2b-256 checksum
How to use checksums
2e305cdf89417deddb0f4b04dad975195e592d0d3ef841b581be74ccb25a1d6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 20, 2026.

Transparency log

Release files / statewire-0.24.2-py3-none-any.whl

Download URL statewire-0.24.2-py3-none-any.whl
Size 83.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cc38f3ab46006f6cdee3deedde2b1769980fff85fafeb62aeafa2eeb268c57ed
BLAKE2b-256 checksum
How to use checksums
6bc8824b589940e1cd408e93d7c5a5060adb031de241856d36f7f3f2749d953a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 20, 2026.

Transparency log

Security for statewire 0.24.2

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 statewire-0.24.2.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 Nov 20, 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.

Release history Release notifications | RSS feed

This release

0.24.2 This release

2 release files Full provenance

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