Official Python client for TofuPilot with OpenHTF integration, real-time streaming and file attachment support
Project description
TofuPilot Python Client
The official Python client for TofuPilot. Integrate your hardware test runs into one app with just a few lines of Python.
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.units |
list, create, get, delete, update, add_child, remove_child |
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.attachments |
initialize, finalize, delete, upload, download |
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")
Upload and download attachments
# Upload a file (one line)
attachment_id = client.attachments.upload("report.pdf")
# Link to a run
client.runs.update(id=run_id, attachments=[attachment_id])
# Download an attachment
client.attachments.download(attachment, dest="local-copy.pdf")
Error Handling
from tofupilot.v2.models.errors import ErrorNOTFOUND, ErrorBADREQUEST
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}")
| Exception | Status Code |
|---|---|
ErrorBADREQUEST |
400 |
ErrorUNAUTHORIZED |
401 |
ErrorFORBIDDEN |
403 |
ErrorNOTFOUND |
404 |
ErrorCONFLICT |
409 |
ErrorUNPROCESSABLECONTENT |
422 |
ErrorINTERNALSERVERERROR |
500 |
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tofupilot-2.2.3.tar.gz.
File metadata
- Download URL: tofupilot-2.2.3.tar.gz
- Upload date:
- Size: 105.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d1830d177dee773b97cbaeec7e5ac6042d4954f9c84bb032eafc3781706a56d
|
|
| MD5 |
3a3f1eee5501cf0f3f8f67ea56656c85
|
|
| BLAKE2b-256 |
0e47a5f6dc15353f4e66c390ce6353aabce1c1e0cbc8636e767afcead7a0a4b5
|
Provenance
The following attestation bundles were made for tofupilot-2.2.3.tar.gz:
Publisher:
release-python-client.yml on tofupilot/tofupilot
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tofupilot-2.2.3.tar.gz -
Subject digest:
6d1830d177dee773b97cbaeec7e5ac6042d4954f9c84bb032eafc3781706a56d - Sigstore transparency entry: 1216143740
- Sigstore integration time:
-
Permalink:
tofupilot/tofupilot@22155d11a892b28fb265769c759add2352c4fcb4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/tofupilot
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-python-client.yml@22155d11a892b28fb265769c759add2352c4fcb4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tofupilot-2.2.3-py3-none-any.whl.
File metadata
- Download URL: tofupilot-2.2.3-py3-none-any.whl
- Upload date:
- Size: 172.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1dec31ffd79a46e170608367e98a5fd64ff1675107f4863b9f45cd4ba2450dc5
|
|
| MD5 |
209b55a4f24135e6bc9527ceb9a76e54
|
|
| BLAKE2b-256 |
1dd487aadaf2ab74eb5cae84efff2a3e6be2ca97b8c35a16b3219aba8944f067
|
Provenance
The following attestation bundles were made for tofupilot-2.2.3-py3-none-any.whl:
Publisher:
release-python-client.yml on tofupilot/tofupilot
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tofupilot-2.2.3-py3-none-any.whl -
Subject digest:
1dec31ffd79a46e170608367e98a5fd64ff1675107f4863b9f45cd4ba2450dc5 - Sigstore transparency entry: 1216143842
- Sigstore integration time:
-
Permalink:
tofupilot/tofupilot@22155d11a892b28fb265769c759add2352c4fcb4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/tofupilot
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-python-client.yml@22155d11a892b28fb265769c759add2352c4fcb4 -
Trigger Event:
push
-
Statement type: