Skip to main content

TofuPilot Python SDK

PyPI version License: MIT Tests

The official Python SDK for TofuPilot. Integrate your hardware test runs into one app with just a few lines of Python.

Writing a new test procedure?

Use the TofuPilot Framework, not this package: install the TofuPilot CLI and run tofupilot init in an empty folder. It writes a procedure.yaml with Python phases and a mock plug that run offline, plus an AGENTS.md that tells coding agents how to validate, run and debug it with the CLI (tofupilot docs, tofupilot validate --json, tofupilot run --json).

This SDK is for sending runs from code you already have: the TofuPilot REST API, and the OpenHTF integration below.

Installation

pip install tofupilot

Quick Start

import os
from tofupilot.v2 import TofuPilot

with TofuPilot(api_key=os.getenv("TOFUPILOT_API_KEY")) as client:
    run = client.runs.create(
        procedure_id="your-procedure-id",
        serial_number="SN001",
        part_number="PN001",
        outcome="PASS",
    )
    print(f"Run created: {run.id}")

Authentication

Set your API key as an environment variable:

export TOFUPILOT_API_KEY="your-api-key"

Or pass it directly:

client = TofuPilot(api_key="your-api-key")

To point to a different server (e.g. self-hosted):

client = TofuPilot(api_key="your-api-key", server_url="https://your-instance.com/api")

Available Resources

Resource Operations
client.runs list, create, get, delete, update
client.runs.attachments upload, download
client.units list, create, get, delete, update, add_child, remove_child
client.units.attachments upload, download, delete
client.parts list, create, get, delete, update
client.parts.revisions create, get, delete, update
client.procedures list, create, get, delete, update
client.procedures.versions create, get, delete
client.batches list, create, get, delete, update
client.stations list, create, get, get_current, remove, update
client.user list

Usage Examples

Create a run with measurements

from datetime import datetime, timedelta, timezone

run = client.runs.create(
    procedure_id=procedure_id,
    serial_number="SN-001",
    part_number="PCB-V1",
    outcome="PASS",
    started_at=datetime.now(timezone.utc) - timedelta(minutes=5),
    ended_at=datetime.now(timezone.utc),
    phases=[{
        "name": "Voltage Test",
        "outcome": "PASS",
        "started_at": datetime.now(timezone.utc) - timedelta(minutes=5),
        "ended_at": datetime.now(timezone.utc),
        "measurements": [{
            "name": "Output Voltage",
            "outcome": "PASS",
            "measured_value": 3.3,
            "units": "V",
            "validators": [
                {"operator": ">=", "expected_value": 3.0},
                {"operator": "<=", "expected_value": 3.6},
            ],
        }],
    }],
)

List and filter runs

result = client.runs.list(
    part_numbers=["PCB-V1"],
    outcomes=["PASS"],
    limit=10,
)

for run in result.data:
    print(f"{run.id} — {run.unit.serial_number}")

Manage units and sub-units

# Create part and revision
client.parts.create(number="PCB-V1", name="Main Board")
client.parts.revisions.create(part_number="PCB-V1", number="REV-A")

# Create units
client.units.create(serial_number="PARENT-001", part_number="PCB-V1", revision_number="REV-A")
client.units.create(serial_number="CHILD-001", part_number="PCB-V1", revision_number="REV-A")

# Link parent-child
client.units.add_child(serial_number="PARENT-001", child_serial_number="CHILD-001")

Attach files to runs and units

# Upload a file to a run
client.runs.attachments.upload(id=run_id, file="report.pdf")

# Upload a file to a unit
client.units.attachments.upload(serial_number="SN-0001", file="calibration.pdf")

# Download an attachment
run = client.runs.get(id=run_id)
client.runs.attachments.download(run.attachments[0], dest="local-copy.pdf")

# Delete a unit attachment
client.units.attachments.delete(serial_number="SN-0001", ids=[attachment_id])

Error Handling

from tofupilot.v2.errors import ErrorNOTFOUND, ErrorBADREQUEST, ErrorTIMEOUT

try:
    client.runs.get(id="nonexistent-id")
except ErrorNOTFOUND as e:
    print(f"Not found: {e.message}")
except ErrorBADREQUEST as e:
    print(f"Bad request: {e.message}")
except ErrorTIMEOUT as e:
    # A read query exceeded the server statement cap: narrow the window and retry
    print(f"Timeout: {e.message}")
Exception Status Code
ErrorBADREQUEST 400
ErrorUNAUTHORIZED 401
ErrorFORBIDDEN 403
ErrorNOTFOUND 404
ErrorTIMEOUT 408
ErrorCONFLICT 409
ErrorUNPROCESSABLECONTENT 422
ErrorINTERNALSERVERERROR 500
ErrorBADGATEWAY 502

Running Tests

cd clients/python-speakeasy
cp tests/.env.local.example tests/.env.local  # Set your API key and URL
python -m pytest tests/v2/

Documentation

License

MIT

Metadata

Release files for tofupilot 2.31.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 tofupilot 2.31.0
File Size Uploaded Provenance Actions
tofupilot-2.31.0.tar.gz 155.0 kB With provenance Details for tofupilot-2.31.0.tar.gz

Built distribution (wheel)

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

Total release size: 400.8 kB

Release files / tofupilot-2.31.0.tar.gz

Download URL tofupilot-2.31.0.tar.gz
Size 155.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9615feaedb1749f5586282973e8e3960aa13e91decc70e20ba137b715e520878
BLAKE2b-256 checksum
How to use checksums
2a2c014804f6842e52528fd7407443396a26e3c6d766bf085891379cdf0d0938
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 23, 2026.

Transparency log

Release files / tofupilot-2.31.0-py3-none-any.whl

Download URL tofupilot-2.31.0-py3-none-any.whl
Size 245.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3a51e6829a56746266a9da219c7de7887b6879100bce0b906fa2aae861c5064a
BLAKE2b-256 checksum
How to use checksums
5dfbe0cdd3bd89e263cdadbc72d2afffd5f6bd39caa24f6faaf416474f9a7014
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 23, 2026.

Transparency log

Security for tofupilot 2.31.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 tofupilot-2.31.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 Nov 23, 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

2.31.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