Python SDK for Crash Lab trace recording and uploads
Project description
Crash Lab Python SDK
Python SDK for recording Crash Lab traces and uploading them to a Crash Lab API.
Install
pip install -e sdk
Quick start
from crashlab_sdk import CrashLabClient, crashlab_trace
client = CrashLabClient(
base_url="http://localhost:8000",
api_key="crashlab-dev-key",
project_id="22222222-2222-2222-2222-222222222222",
)
with crashlab_trace("example_task", {"user_id": "u-123"}) as rec:
rec.model_step("plan", {"goal": "create issue"}, output={"ok": True})
rec.tool_call("jira.create_issue(commit)", {"summary": "SDK test"})
rec.tool_result("jira.create_issue(commit)", {"issue_id": "OPS-123"})
trace_id = client.upload_trace(rec.to_trace())
print("trace_id:", trace_id)
API
CrashLabClient
CrashLabClient(base_url, api_key=None, project_id=None, timeout=30)
Methods:
upload_trace(trace: dict) -> strcreate_campaign(name, mutation_set, eval_set, mutation_pack_id=None) -> strstart_run(trace_id, campaign_id, thresholds=None) -> strget_run(run_id) -> dict
TraceBuilder
TraceBuilder outputs backend-compatible traces:
{
"trace_version": "0.1",
"source": "sdk",
"task": {"name": "...", "input": {}},
"events": []
}
Recorder
Use a context manager:
from crashlab_sdk import crashlab_trace
with crashlab_trace("task_name", {"input": "value"}) as rec:
rec.model_step("name", {"foo": "bar"}, output={"ok": True})
rec.tool_call("tool.name", {"arg": 1})
rec.tool_result("tool.name", {"result": "ok"})
rec.error(message="something happened", tool="tool.name")
Decorator
from crashlab_sdk import record_trace
@record_trace(client=client, campaign_id="<campaign_id>")
def run_business_logic(x: int) -> int:
return x * 2
The decorator preserves the function return value and attempts to upload/start runs in the background path without interrupting normal execution.
Example script
See examples/sdk_demo.py.
python sdk/examples/sdk_demo.py
Optional environment variables:
CRASHLAB_API_BASE_URL(defaulthttp://localhost:8000)CRASHLAB_UI_BASE_URL(defaulthttp://localhost:3000)CRASHLAB_API_KEYCRASHLAB_PROJECT_IDCRASHLAB_CAMPAIGN_ID(if provided, script starts a run)
Publish to PyPI (CI)
This repository includes .github/workflows/sdk-publish-pypi.yml to publish the SDK directly to PyPI.
Setup:
- Add
PYPI_API_TOKENin GitHub repository secrets. - Ensure the package version in
sdk/pyproject.tomlis new.
Release:
- Push a tag like
sdk-v0.1.1to trigger publish. - Or run the workflow manually from GitHub Actions.
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 crashlab_sdk-0.1.1.tar.gz.
File metadata
- Download URL: crashlab_sdk-0.1.1.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4fc29c461d6b7d290153daee8975a5be94b9ee6625b8e252f9dfdcad405e49fc
|
|
| MD5 |
9d3726f9fd832665abbd514c43d747ec
|
|
| BLAKE2b-256 |
ae4e7ee00360a43848f0392402b332bda49b2eaa968d7aefabb5d21cd5e05957
|
File details
Details for the file crashlab_sdk-0.1.1-py3-none-any.whl.
File metadata
- Download URL: crashlab_sdk-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3fe0e0aa0189e4af0373993df53be7fb15d4e569bc86ecb1d50531027fd4b641
|
|
| MD5 |
6ef0632d4cecb7df2354920be1d1d351
|
|
| BLAKE2b-256 |
7cacb5debd03fe4ec91d535d48954705f7b7c05c0b048c767a86fe4af14c27de
|