Skip to main content

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) -> str
  • create_campaign(name, mutation_set, eval_set, mutation_pack_id=None) -> str
  • start_run(trace_id, campaign_id, thresholds=None) -> str
  • get_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 (default http://localhost:8000)
  • CRASHLAB_UI_BASE_URL (default http://localhost:3000)
  • CRASHLAB_API_KEY
  • CRASHLAB_PROJECT_ID
  • CRASHLAB_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_TOKEN in GitHub repository secrets.
  • Ensure the package version in sdk/pyproject.toml is new.

Release:

  • Push a tag like sdk-v0.1.1 to trigger publish.
  • Or run the workflow manually from GitHub Actions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

crashlab_sdk-0.1.1.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

crashlab_sdk-0.1.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

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

Hashes for crashlab_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4fc29c461d6b7d290153daee8975a5be94b9ee6625b8e252f9dfdcad405e49fc
MD5 9d3726f9fd832665abbd514c43d747ec
BLAKE2b-256 ae4e7ee00360a43848f0392402b332bda49b2eaa968d7aefabb5d21cd5e05957

See more details on using hashes here.

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

Hashes for crashlab_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3fe0e0aa0189e4af0373993df53be7fb15d4e569bc86ecb1d50531027fd4b641
MD5 6ef0632d4cecb7df2354920be1d1d351
BLAKE2b-256 7cacb5debd03fe4ec91d535d48954705f7b7c05c0b048c767a86fe4af14c27de

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page