Metadata-Version: 2.5
Name: haaslab
Version: 0.1.0
Summary: Python SDK for the haas-lab hardware-as-a-service API
Project-URL: Homepage, https://haas-lab.com
Project-URL: Documentation, https://haas-lab.com/docs
License: MIT
Requires-Python: >=3.9
Requires-Dist: httpx-sse>=0.4.0
Requires-Dist: httpx>=0.27.0
Provides-Extra: dev
Requires-Dist: pytest-httpx>=0.30.0; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Description-Content-Type: text/markdown

# haaslab Python SDK

Python client for the [haas-lab](https://haas-lab.com) hardware-as-a-service API.

## Install

```bash
pip install haaslab
```

Requires Python 3.9+. You need a Personal Access Token: create one at
https://haas-lab.com/dashboard/tokens after signing in.

## Quickstart

```python
from haaslab import Client

c = Client(token="pat_xxx")              # or set HAASLAB_TOKEN and call Client()
job = c.jobs.create("blink.bin")          # multipart upload
job = c.jobs.wait(job.id, timeout=120)    # poll until terminal
print(c.jobs.serial(job.id))              # full archived log
```

## Live streaming

```python
for line in c.jobs.stream_serial(job.id):
    print(line)
```

## Token management

```python
tok = c.tokens.create("ci-bot")
print(tok.token)          # plaintext PAT — shown once

c.tokens.list()           # list all tokens
c.tokens.revoke(tok.id)   # revoke a token
```

## API Reference

### `Client(token, base_url, timeout)`

| Param | Default | Description |
|---|---|---|
| `token` | `$HAASLAB_TOKEN` | Personal Access Token (`pat_xxx`); `ValueError` if neither is set |
| `base_url` | `$HAASLAB_BASE_URL`, else `https://haas-lab.com` | Base URL of the server |
| `timeout` | `30.0` | HTTP request timeout in seconds |

### `client.jobs`

| Method | Returns | Description |
|---|---|---|
| `create(firmware, name=None, *, profile_key=None, device_id=None, expected_runtime_s=None)` | `Job` | Upload a firmware `.bin` and queue it; `profile_key` asks for any board of that profile, `device_id` for one board, `expected_runtime_s` is the run time you book |
| `get(job_id)` | `Job` | Fetch job by ID |
| `list(limit=20, page=1)` | `list[Job]` | List jobs (paginated) |
| `serial(job_id)` | `str` | Full archived serial log |
| `stream_serial(job_id)` | `Iterator[str]` | Live SSE serial lines |
| `wait(job_id, timeout=120)` | `Job` | Poll until COMPLETED/FAILED/CANCELLED |

### `client.tokens`

| Method | Returns | Description |
|---|---|---|
| `list()` | `list[Token]` | List PATs (no plaintext) |
| `create(name)` | `CreatedToken` | Create PAT (plaintext in `.token`, shown once) |
| `revoke(id)` | `None` | Revoke a PAT |

### Exceptions

| Exception | HTTP status |
|---|---|
| `AuthError` | 401 |
| `NotFoundError` | 404 |
| `RateLimitError` | 429 |
| `ServerError` | 5xx |
| `HaasLabError` | base class / other 4xx |

## Environment variables

`Client()` reads these when `token` or `base_url` is not passed:

```bash
export HAASLAB_TOKEN=pat_xxx                    # your Personal Access Token
export HAASLAB_BASE_URL=http://localhost:3000   # optional; defaults to https://haas-lab.com
```

## Development

```bash
pip install -e ".[dev]"
pytest -v
```
