Skip to main content

herdr-python-sdk

An independent Python 3.12+ SDK for Herdr socket protocol 22. The package provides synchronous and asynchronous calls, typed Pydantic models, event subscriptions, and graphics streams. It uses Unix sockets on macOS and Linux and native named pipes on Windows. This project is not maintained by the Herdr project.

Install

python -m pip install herdr-python-sdk

Herdr 0.9.0 or another server that implements socket protocol 22 must already be running.

from herdr_sdk import __version__

print(__version__)

Read workspaces

from herdr_sdk import HerdrClient, models

with HerdrClient() as client:
    result = client.workspace_list()
    if isinstance(result, models.WorkspaceListResponse):
        for workspace in result.workspaces:
            print(workspace)
import asyncio
from herdr_sdk import AsyncHerdrClient, models

async def main():
    async with AsyncHerdrClient(session="default") as client:
        result = await client.workspace_list()
        if isinstance(result, models.WorkspaceListResponse):
            print(result.workspaces)

asyncio.run(main())

Socket method names use underscores in Python: pane.read becomes pane_read. All 102 schema methods are declared in client.py. Use the parameter classes in models.py:

with HerdrClient() as client:
    result = client.pane_read(
        models.PaneReadParams(pane_id="w1:p1", source=models.ReadSource.recent)
    )
    if isinstance(result, models.PaneReadResponse):
        print(result.read.text)

Methods return the schema's result union. Check the response class before using its fields. Server fields unknown to the pinned schema remain in model_extra. For dictionary inputs, use client.request("pane.read", {"pane_id": "w1:p1", "source": "recent"}). Only protocol 22 method names are accepted.

Select a session

Pass either socket_path or session; passing both raises ValueError. With neither set, HERDR_SOCKET_PATH takes precedence, followed by HERDR_SESSION (default: default). Session names contain 1 to 64 ASCII letters, digits, dots, underscores, or hyphens; . and .. are invalid.

Discovery uses XDG_CONFIG_HOME/herdr, then the platform's user config directory. The default session uses herdr.sock; named sessions use sessions/<session>/herdr.sock. On Windows, pass Herdr's socket identity, not an already prefixed pipe name. The transport adds \\.\pipe\. Windows async callers must use asyncio.ProactorEventLoop.

Events

from herdr_sdk import HerdrClient, models

with HerdrClient() as client:
    params = models.EventsSubscribeParams(
        subscriptions=[models.WorkspaceRenamedSubscription()]
    )
    with client.events_subscribe(params, timeout=60) as events:
        for event in events:
            print(event.event, event.data)

Async callers use async with await client.events_subscribe(params) and async for event in events. Both ordinary events and dotted subscription events return typed envelopes. Leaving the context closes the subscription.

Graphics streams

from herdr_sdk import HerdrClient, GraphicsFrame, GraphicsStreamParams, models

frame = GraphicsFrame(
    format=models.PaneGraphicsFormat.rgba, image_width=1, image_height=1
)
with HerdrClient() as client:
    with client.pane_graphics_stream(GraphicsStreamParams(pane_id="w1:p1")) as stream:
        stream.send_frame(frame, b"\xff\x00\x00\xff")

pane.graphics.stream is public in Herdr 0.9.0 but absent from its JSON schema. The SDK implements its JSON headers and raw byte payloads directly. Inline frames are limited to 16 MiB. Inline success has no server acknowledgement, so a completed send proves transmission only. Subsequent operations report received server errors. Closing the stream releases its layer.

For file frames, call stream.send_file(frame, path, sequence=1, revision=1). The file must contain raw RGBA or BGRA pixels and remain unchanged until the matching acknowledgement returns. The SDK checks its request ID, sequence, and revision. It does not create or remove the file. After a failed call, do not assume the server has released it. Async streams provide the same methods with await.

Timeouts, errors, and lifetime

Each operation first checks ping for protocol 22. A mismatch raises HerdrProtocolMismatchError before sending the requested action. Ordinary calls use one connection each after the preflight. There is no reconnect or replay.

The connect timeout is 5 seconds. The ordinary request and preflight timeout is 30 seconds. Set timeout=None for no read deadline or pass a positive timeout per method. Each preflight has its own deadline. Waiting methods (agent.start, agent.wait, events.wait, pane.wait_for_output, and agent.prompt with wait) have no read deadline by default. Subscriptions use the client timeout for their initial acknowledgement and no deadline for later events unless one is supplied. Responses default to a 32 MiB limit; use max_response_bytes to change it.

HerdrAPIError retains code, message, and request_id. Transport, timeout, invalid-response, and version failures have separate HerdrError subclasses. Invalid caller parameters raise Pydantic ValidationError or ValueError.

Keep each async client on one event loop and each sync client on one thread. Use the async client inside an active event loop. Context managers close sockets and streams; closing an async client also cancels its active requests.

Enable the herdr_sdk logger at DEBUG to see method names, target IDs, request IDs, byte counts, and timing. Logs do not include terminal text or frame contents.

Source and development

The schema and stream contract are pinned to Herdr 0.9.0, commit b99002ac99b09e00b4ca692436cb15a6b0d676f1. See the official Herdr socket API. The vendored schema carries the upstream Apache 2.0 license. client_shell.surface.set is exposed because it is in the schema, but the normal socket server rejects it with connection_local_only.

SDK versions follow Semantic Versioning independently of Herdr versions. See the changelog for protocol compatibility and release details.

Install this checkout for development:

python -m pip install .
uv sync --locked
uv run --locked python scripts/generate.py --check
uv run --locked ruff check src scripts tests
uv run --locked ruff format --check src scripts tests
uv run --locked mypy src
uv run --locked pytest -q
uv build --no-sources

To rebuild the committed declarations after a deliberate schema update, run uv run --locked python scripts/generate.py. Generation uses the vendored schema and the locked vendor model generator. Tests use an independent local socket server. The GitHub Actions matrix covers Python 3.12, 3.13, and 3.14 on macOS, Linux, and Windows; a configured matrix is not evidence that those jobs have run.

Metadata

Release files for herdr-python-sdk 0.1.0

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

Source distribution (sdist)

Source distribution for herdr-python-sdk 0.1.0
File Size Uploaded Provenance Actions
herdr_python_sdk-0.1.0.tar.gz 51.8 kB With provenance Details for herdr_python_sdk-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for herdr-python-sdk 0.1.0
File Interpreter ABI Platform Actions
herdr_python_sdk-0.1.0-py3-none-any.whl Python 3 none any Details for herdr_python_sdk-0.1.0-py3-none-any.whl

Total release size: 89.4 kB

Release files / herdr_python_sdk-0.1.0.tar.gz

Download URL herdr_python_sdk-0.1.0.tar.gz
Size 51.8 kB
Tags Source
SHA-256 checksum
How to use checksums
50a84f47eb0cd844ad9d8313604777be402e3e5ad333ff9aa1b31ce4c77a1a2f
BLAKE2b-256 checksum
How to use checksums
362badf1ac6d9452ab8d27d1494441d4341ca4c3ccc6ed03b5eb6473970b07e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 11, 2026.

Transparency log

Release files / herdr_python_sdk-0.1.0-py3-none-any.whl

Download URL herdr_python_sdk-0.1.0-py3-none-any.whl
Size 37.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f39791c43a248d78bef858db8901d42fc01b59c833d445c07032d81f407029ad
BLAKE2b-256 checksum
How to use checksums
4d6399345fcd6c7e55c4a8c0316ee4f80122a462cbb401725f308e9f2cb35583
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 11, 2026.

Transparency log

Security for herdr-python-sdk 0.1.0

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 herdr_python_sdk-0.1.0.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 Sep 11, 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.1.0 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