---
title: Job runs and logs
description: Job runs and logs in the dltHub Runtime Python SDK (dlthub_sdk)
keywords: [dlthub, runtime, python sdk, dlthub_sdk, api]
---
# Job runs and logs

<!-- generated from dlthub-client 0.33.1, do not edit -->

New to the SDK? [Getting started](getting-started.md) shows how to connect and use it.

## Job runs

### `JobRuns` {#jobruns}

The job runs of one workspace, or of one job in it.

#### `JobRuns.get()` {#jobruns-get}

```python
get(*, id: str) -> JobRun
```

Return one job run by ID.

Job runs are addressed by UUID. `list()` with `number` finds one by
its number.

**Arguments**

| Name | Type | Description |
| --- | --- | --- |
| `id` | <code>str</code> | The UUID of the job run. |

**Returns:** <code><a href="#jobrun">JobRun</a></code> — The job run. Async mode returns an awaitable.

**Raises**

| Exception | When |
| --- | --- |
| [`BadRequest`](errors.md#badrequest) | The runtime rejected the request as invalid. `message`, `code` and `fields` say why. |
| [`NotFound`](errors.md#notfound) | The job run does not exist in this workspace. |
| [`ScopeMissing`](errors.md#scopemissing) | No workspace in scope. |

#### `JobRuns.result()` {#jobruns-result}

```python
result(*, id: str) -> JobResult
```

Read the declared result of one job run, without reading the job run.

**Arguments**

| Name | Type | Description |
| --- | --- | --- |
| `id` | <code>str</code> | The UUID of the job run. |

**Returns:** <code><a href="#jobresult">JobResult</a></code> — The result. Async mode returns an awaitable.

**Raises**

| Exception | When |
| --- | --- |
| [`BadRequest`](errors.md#badrequest) | The runtime rejected the request as invalid. `message`, `code` and `fields` say why. |
| [`NotFound`](errors.md#notfound) | The job run does not exist or declared no result. The runtime answers the same for both. |
| [`ScopeMissing`](errors.md#scopemissing) | No workspace in scope. |

#### `JobRuns.trace()` {#jobruns-trace}

```python
trace(*, id: str) -> JobResultTrace
```

Read the whole result of one job run, without reading the job run.

**Arguments**

| Name | Type | Description |
| --- | --- | --- |
| `id` | <code>str</code> | The UUID of the job run. |

**Returns:** <code><a href="#jobresulttrace">JobResultTrace</a></code> — The whole result. Async mode returns an awaitable.

**Raises**

| Exception | When |
| --- | --- |
| [`ApiError`](errors.md#apierror) | The result is too large to serve (`code` `job_result_trace_too_large`). `result()` still reads the summary fields. |
| [`BadRequest`](errors.md#badrequest) | The runtime rejected the request as invalid. `message`, `code` and `fields` say why. |
| [`NotFound`](errors.md#notfound) | The job run does not exist or declared no result. The runtime answers the same for both. |
| [`ScopeMissing`](errors.md#scopemissing) | No workspace in scope. |

#### `JobRuns.latest()` {#jobruns-latest}

```python
latest(*, job_id: str | None = None) -> JobRun
```

Return the latest job run.

**Arguments**

| Name | Type | Description |
| --- | --- | --- |
| `job_id` | <code>str &#124; None</code> | Only the job runs of this job. `None` uses the job in scope, or else the whole workspace without system jobs such as the workspace dashboard. |

**Returns:** <code><a href="#jobrun">JobRun</a></code> — The newest job run. Async mode returns an awaitable.

**Raises**

| Exception | When |
| --- | --- |
| [`BadRequest`](errors.md#badrequest) | The runtime rejected the request as invalid. `message`, `code` and `fields` say why. |
| [`NotFound`](errors.md#notfound) | The workspace or the job has no job run yet. |
| [`ScopeMissing`](errors.md#scopemissing) | No workspace in scope. |

#### `JobRuns.count()` {#jobruns-count}

```python
count(*, job_id: str | None = None) -> int
```

Return the number of job runs, without reading them.

**Arguments**

| Name | Type | Description |
| --- | --- | --- |
| `job_id` | <code>str &#124; None</code> | Only the job runs of this job. `None` uses the job in scope, or else the whole workspace without system jobs such as the workspace dashboard. |

**Returns:** <code>int</code> — The count, which saturates at 10,001. Async mode returns an awaitable.

**Raises**

| Exception | When |
| --- | --- |
| [`BadRequest`](errors.md#badrequest) | The runtime rejected the request as invalid. `message`, `code` and `fields` say why. |
| [`ScopeMissing`](errors.md#scopemissing) | No workspace in scope. |

#### `JobRuns.list()` {#jobruns-list}

```python
list(
    *,
    job_id: str | None = None,
    number: int | None = None,
    limit: int | None = None,
    offset: int = 0,
) -> Iterable[JobRun] | AsyncIterable[JobRun]
```

Yield job runs newest first, page by page.

Errors from the runtime raise when the iteration starts, not in this call.

**Arguments**

| Name | Type | Description |
| --- | --- | --- |
| `job_id` | <code>str &#124; None</code> | Only the job runs of this job. `None` uses the job in scope, or else the whole workspace without system jobs such as the workspace dashboard. |
| `number` | <code>int &#124; None</code> | Only the job run with this number. Numbers repeat across jobs, so this filter needs a job. |
| `limit` | <code>int &#124; None</code> | The most items to return. `None` returns every item up to item 10,100, where the runtime stops paging. |
| `offset` | <code>int</code> | The number of items that the runtime skips first. |

**Returns:** <code>Iterable[<a href="#jobrun">JobRun</a>] &#124; AsyncIterable[<a href="#jobrun">JobRun</a>]</code> — An iterable of job runs. Async mode returns an async iterable.

**Raises**

| Exception | When |
| --- | --- |
| [`BadRequest`](errors.md#badrequest) | The runtime rejected the request as invalid. `message`, `code` and `fields` say why. |
| [`ScopeMissing`](errors.md#scopemissing) | No workspace in scope. |
| `ValueError` | A negative `limit` or `offset`. |

#### `JobRuns.cancel_all()` {#jobruns-cancel_all}

```python
cancel_all(*, job_refs: Sequence[str], dry_run: bool = False) -> CancelReport
```

Stop the active job runs of the named jobs.

It addresses jobs, not job runs: it cancels every pending, starting or
running job run of the named jobs. A ref that names no job, or has no
active job run, is in `not_running`.

**Arguments**

| Name | Type | Description |
| --- | --- | --- |
| `job_refs` | <code>Sequence[str]</code> | The jobs whose job runs to stop. |
| `dry_run` | <code>bool</code> | Whether to only report the plan. A dry run stops no job run. |

**Returns:** <code><a href="#cancelreport">CancelReport</a></code> — What the call cancelled and what was not running. Async mode returns an awaitable.

**Raises**

| Exception | When |
| --- | --- |
| `ValueError` | No job refs were given. |
| [`ScopeMissing`](errors.md#scopemissing) | No workspace in scope. |

### `JobRun` {#jobrun}

One execution of a job.

**Attributes**

| Name | Type | Description |
| --- | --- | --- |
| `number` | <code>int</code> | Number of the run within its job, counting up from 1; numbers repeat across jobs. |
| `id` | <code>str</code> | Unique ID (a UUID). |
| `job_ref` | <code>str</code> | Canonical job reference, unique per workspace. |
| `status` | <code><a href="#jobrunstatus">JobRunStatus</a></code> | The status of the run. |
| `trigger` | <code>str</code> | The trigger the run fired with, e.g. `schedule:0 8 * * *`, `manual:jobs.my_job`, `job.success:jobs.upstream`. |
| `profile` | <code>str</code> | The name of the profile that was used for the run. |
| `started_at` | <code>datetime &#124; None</code> | When the run started; `None` until it has. |
| `finished_at` | <code>datetime &#124; None</code> | When the run finished; `None` until it has. |
| `duration_seconds` | <code>float &#124; None</code> | Duration of the run in seconds, possibly fractional; `None` until it has finished. |
| `max_run_time_seconds` | <code>int &#124; None</code> | Maximum allowed run duration in seconds for this job version. |
| `interval_start` | <code>datetime &#124; None</code> | Start of the interval the run processes; `None` for a job without intervals. |
| `interval_end` | <code>datetime &#124; None</code> | End of the interval the run processes; `None` for a job without intervals. |
| `pipeline_run_summaries` | <code>tuple[<a href="#pipelinerunsummary">PipelineRunSummary</a>, ...]</code> | One entry per dlt pipeline name the run reported; a pipeline that ran more than once shows its latest report. In no particular order, and empty until telemetry has received the reports. |
| `previous_job_run_id` | <code>str &#124; None</code> | The upstream run whose completion started this one, through a `job.success:` / `job.fail:` trigger or a freshness dependency; `None` for a run started manually, by its own schedule, or by a trigger request. |
| `created_at` | <code>datetime</code> | When it was created. |
| `finished` | <code>bool</code> | Whether the status can no longer change. |
| `failed` | <code>bool</code> | Whether the job run finished without success. |

#### `JobRun.cancel()` {#jobrun-cancel}

```python
cancel() -> JobRun
```

Ask the runtime to stop this job run.

The job run moves to `CANCELLING` first, and to `CANCELLED` when it
stops.

**Returns:** <code><a href="#jobrun">JobRun</a></code> — A fresh snapshot, usually `CANCELLING` and not `CANCELLED`. Async mode returns an awaitable.

**Raises**

| Exception | When |
| --- | --- |
| [`BadRequest`](errors.md#badrequest) | The runtime rejected the request, for example because the job run already finished or is cancelling. `message`, `code` and `fields` say why. |
| [`Conflict`](errors.md#conflict) | The current state does not allow the call, for example an archived workspace. `code` and `message` say why. |
| [`NotFound`](errors.md#notfound) | The job run no longer exists. |

#### `JobRun.logs()` {#jobrun-logs}

```python
logs() -> Iterable[LogLine] | AsyncIterable[LogLine]
```

Read the stored log of the job run, oldest line first.

Lines arrive as the body does, so a long log is never held whole. The
runtime stores the complete log after the job run ends. Until then, this
call raises. `stream_logs()` follows a live job run. Errors from the
runtime raise when the iteration starts, not in this call.

**Returns:** <code>Iterable[<a href="#logline">LogLine</a>] &#124; AsyncIterable[<a href="#logline">LogLine</a>]</code> — An iterable of log lines. Async mode returns an async iterable.

**Raises**

| Exception | When |
| --- | --- |
| [`NotFound`](errors.md#notfound) | The job run has no stored log, because it does not exist or because the runtime did not store the complete log yet. |
| [`ScopeMissing`](errors.md#scopemissing) | No workspace in scope. |

#### `JobRun.stream_logs()` {#jobrun-stream_logs}

```python
stream_logs(*, follow: bool = True) -> Iterable[LogLine] | AsyncIterable[LogLine]
```

Follow the log of the job run live, until it reaches a terminal status.

It reads the live log, so it works while the job run is active and stops
when the job run ends. The runtime waits up to about a minute for a backend
that did not start to report yet. Errors from the runtime raise when the
iteration starts, not in this call.

**Arguments**

| Name | Type | Description |
| --- | --- | --- |
| `follow` | <code>bool</code> | Whether to read until the job run ends. False replays the reported lines and stops. The runtime does not mark the end, so a slow producer can end it early. |

**Returns:** <code>Iterable[<a href="#logline">LogLine</a>] &#124; AsyncIterable[<a href="#logline">LogLine</a>]</code> — An iterable of log lines. Async mode returns an async iterable.

**Raises**

| Exception | When |
| --- | --- |
| [`ApiError`](errors.md#apierror) | The runtime did not follow this job run. The job run is unknown, its backend never reported, its backend has no live logs, or the stream failed. The runtime reports this inside a successful response, so the error can come after some lines. |
| [`ScopeMissing`](errors.md#scopemissing) | No workspace in scope. |

#### `JobRun.wait()` {#jobrun-wait}

```python
wait(*, timeout: float | None = None) -> JobRun
```

Poll until the job run stops changing, and return its final state.

It stops at any terminal status, so a failed or cancelled job run returns
and does not raise. `status` tells which status it is. It checks
about every second at first, then backs off to every ten seconds. A short
job run returns almost at once, and a long one costs few requests.

**Arguments**

| Name | Type | Description |
| --- | --- | --- |
| `timeout` | <code>float &#124; None</code> | The most seconds to wait. `None`, the default, waits until the job run ends. |

**Returns:** <code><a href="#jobrun">JobRun</a></code> — A snapshot in a terminal status. Async mode returns an awaitable.

**Raises**

| Exception | When |
| --- | --- |
| [`NotFound`](errors.md#notfound) | The job run no longer exists. |
| [`ScopeMissing`](errors.md#scopemissing) | No workspace in scope. |
| `ValueError` | A negative `timeout`. |
| [`WaitTimeout`](errors.md#waittimeout) | The job run was still active at the deadline. Nothing cancels it, so a retry of the wait is safe. |

#### `JobRun.result()` {#jobrun-result}

```python
result() -> JobResult
```

Read the structured result that this job run declared.

**Returns:** <code><a href="#jobresult">JobResult</a></code> — The result. Async mode returns an awaitable.

**Raises**

| Exception | When |
| --- | --- |
| [`NotFound`](errors.md#notfound) | The job run declared none. This is the normal case for a job that reports no result, and does not mean that the job run is missing. |
| [`ScopeMissing`](errors.md#scopemissing) | No workspace in scope. |

#### `JobRun.trace()` {#jobrun-trace}

```python
trace() -> JobResultTrace
```

Read the whole result that this job run delivered, trace included.

**Returns:** <code><a href="#jobresulttrace">JobResultTrace</a></code> — The whole result. Async mode returns an awaitable.

**Raises**

| Exception | When |
| --- | --- |
| [`ApiError`](errors.md#apierror) | The result is too large to serve (`code` `job_result_trace_too_large`). `result()` still reads the summary fields. |
| [`NotFound`](errors.md#notfound) | The job run declared no result. This is the normal case for a job that reports none, and does not mean that the job run is missing. |
| [`ScopeMissing`](errors.md#scopemissing) | No workspace in scope. |

### `CancelledRun` {#cancelledrun}

One job run that a bulk cancel stopped.

**Attributes**

| Name | Type | Description |
| --- | --- | --- |
| `job_ref` | <code>str</code> | Job reference of the cancelled run. |
| `job_run_id` | <code>str</code> | ID of the cancelled run. |
| `job_run_number` | <code>int</code> | Number of the run within its job; numbers repeat across jobs. |
| `previous_status` | <code><a href="#jobrunstatus">JobRunStatus</a></code> | Status of the run when the cancel request arrived. |

### `CancelReport` {#cancelreport}

What a bulk cancel did.

**Attributes**

| Name | Type | Description |
| --- | --- | --- |
| `cancelled` | <code>tuple[<a href="#cancelledrun">CancelledRun</a>, ...]</code> | The job runs asked to stop, now cancelling. In a dry run, the job runs that the call selects. |
| `not_running` | <code>tuple[str, ...]</code> | Job refs that had nothing to stop, which is not an error. |

### `JobResult` {#jobresult}

The structured result that a job run declared.

A job run yields at most one, and most do not. A plain pipeline job declares
none, and an agent job reports its own outcome here. The agent fields are
`None` for any other kind of result.

**Attributes**

| Name | Type | Description |
| --- | --- | --- |
| `job_run_id` | <code>str</code> | Job run that declared the result. |
| `job_ref` | <code>str</code> | The job that declared the result. |
| `result_type` | <code>str</code> | `job.{category}.{name}`, for example `job.background_agent.{name}`. |
| `engine_version` | <code>int</code> | Result format version; 1 when not declared. |
| `result` | <code>Any</code> | The job's declared output. Shape is job-defined. |
| `agent_status` | <code>str &#124; None</code> | The agent's self-report, which may legitimately disagree with the run's own status: a failed agent inside a succeeded run is normal. |
| `summary` | <code>str &#124; None</code> | Model-authored markdown, unbounded. Untrusted — render as user content. |
| `model` | <code>str &#124; None</code> | Model the agent ran with. `None` when the result carries no agent trace, as for non-agent jobs. |
| `loop_type` | <code>str &#124; None</code> | Agent loop that ran. `None` when the result carries no agent trace, as for non-agent jobs. |
| `input_tokens` | <code>int &#124; None</code> | Input tokens the agent used. `None` when the result carries no agent trace, as for non-agent jobs. |
| `output_tokens` | <code>int &#124; None</code> | Output tokens the agent used. `None` when the result carries no agent trace, as for non-agent jobs. |
| `total_tokens` | <code>int &#124; None</code> | Total tokens the agent used. `None` when the result carries no agent trace, as for non-agent jobs. |
| `cost_usd` | <code>str &#124; None</code> | Cost in USD the agent reported, as a decimal string. `None` when the result carries no agent trace, as for non-agent jobs. |
| `turn_count` | <code>int &#124; None</code> | Number of turns the agent took. `None` when the result carries no agent trace, as for non-agent jobs. |
| `stop_reason` | <code>str &#124; None</code> | Why the agent stopped. `None` when the result carries no agent trace, as for non-agent jobs. |
| `created_at` | <code>datetime</code> | When the result was first stored, UTC. |
| `updated_at` | <code>datetime</code> | When the result was last stored, UTC. |

### `JobResultTrace` {#jobresulttrace}

The whole job result that a job run delivered, as the job sent it.

[`JobResult`](#jobresult) carries the summary fields. This class carries the whole
result as the job delivered it. This is where the tool calls of an agent run
are, per turn.

**Attributes**

| Name | Type | Description |
| --- | --- | --- |
| `job_run_id` | <code>str</code> | The job run that declared it. |
| `result` | <code>Mapping[str, Any]</code> | The result exactly as delivered: the declared output and, for an agent job, its agent trace (turns, tool calls, token counts, stop reason). The runtime stores it verbatim and declares no shape for it, so the SDK leaves it opaque. |

### `PipelineRunSummary` {#pipelinerunsummary}

One dlt pipeline that a job run ran, as telemetry reported it.

A job run runs every pipeline that its job calls, so a job that loads two
sources reports two. A job run carries one entry per dlt pipeline name that it
reported. A pipeline that ran more than once shows its latest report.
Telemetry adds an entry after the pipeline reports. A new job run has no
entries yet. A job run whose job never reached a pipeline never gets one.

**Attributes**

| Name | Type | Description |
| --- | --- | --- |
| `pipeline_name` | <code>str</code> | Name of the dlt pipeline. |
| `pipeline_run_id` | <code>str &#124; None</code> | Telemetry ID of the pipeline run. |
| `transaction_id` | <code>str &#124; None</code> | Transaction ID of the pipeline run. |
| `destination_name` | <code>str &#124; None</code> | Name of the destination the pipeline wrote to. |
| `dataset_name` | <code>str &#124; None</code> | Name of the dataset the pipeline wrote to. |
| `status` | <code>str &#124; None</code> | What the pipeline run ended as. Free-form: it is dlt's own wording, not [`JobRunStatus`](#jobrunstatus). |
| `total_rows` | <code>int &#124; None</code> | Total number of rows loaded by the pipeline. |
| `duration_ms` | <code>int &#124; None</code> | Duration of the pipeline run in milliseconds. |
| `started_at` | <code>datetime &#124; None</code> | When the pipeline run started. |
| `finished_at` | <code>datetime &#124; None</code> | When the pipeline run finished. |

### `JobRunStatus` {#jobrunstatus}

The state of a job run.

**Members**

| Member | Value | Description |
| --- | --- | --- |
| `PENDING` | `'pending'` | Accepted, not yet started. |
| `STARTING` | `'starting'` | The runtime places it on a compute backend. |
| `RUNNING` | `'running'` | The job run is in progress. |
| `CANCELLING` | `'cancelling'` | A cancel was requested and is not yet effective. |
| `COMPLETED` | `'completed'` | The job run succeeded. |
| `FAILED` | `'failed'` | The job run failed. |
| `CANCELLED` | `'cancelled'` | Stopped on request, or because it exceeded its maximum run time. |
| `SKIPPED` | `'skipped'` | The runtime recorded it but did not run it. The runtime normally reports a declined start through [`TriggerStatus`](jobs.md#triggerstatus) and creates no job run. |
| `UNKNOWN` | `'unknown'` | A status that this SDK version does not know. |

## Logs

### `LogLine` {#logline}

One line that a job run emitted.

**Attributes**

| Name | Type | Description |
| --- | --- | --- |
| `content` | <code>str</code> | Contents of the log message. |
| `line_num` | <code>int</code> | Position of the line in the run's log. |
| `source` | <code><a href="#logsource">LogSource</a></code> | Who emitted the line. |
| `stage` | <code><a href="#logstage">LogStage</a></code> | Stage of the run the line belongs to: `build` (installing dependencies before the job starts) or `run` (the job's execution). |
| `io_stream` | <code><a href="#logiostream">LogIoStream</a></code> | Stream the line was written to: `stdout`, `stderr`, or `other` (a provider's info channel, or a line stored before streams were kept). |
| `reported_at` | <code>datetime</code> | Timestamp when the log was reported. |

### `LogIoStream` {#logiostream}

The stream that a log line went to.

**Members**

| Member | Value | Description |
| --- | --- | --- |
| `STDOUT` | `'stdout'` | Standard output. |
| `STDERR` | `'stderr'` | Standard error. |
| `OTHER` | `'other'` | Neither: an info channel of the compute backend, or a line that the runtime stored before it recorded streams. |
| `UNKNOWN` | `'unknown'` | A stream that this SDK version does not know. |

### `LogSource` {#logsource}

Who emitted a log line.

**Members**

| Member | Value | Description |
| --- | --- | --- |
| `USER` | `'user'` | The code of the user. |
| `SETUP` | `'setup'` | The install and build commands that prepare the job run. |
| `RUNNER` | `'runner'` | The runtime code that starts the code of the user and wraps it. |
| `UNKNOWN` | `'unknown'` | A source that this SDK version does not know. |

### `LogStage` {#logstage}

The stage of the job run that a log line belongs to.

**Members**

| Member | Value | Description |
| --- | --- | --- |
| `BUILD` | `'build'` | The dependencies of the job install before its code runs. |
| `RUN` | `'run'` | The job code runs. |
| `UNKNOWN` | `'unknown'` | A stage that this SDK version does not know. |
