> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tracepress.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Python SDK

> Every public function and method in tracepress.

```python theme={null}
import tracepress as tp
```

## Configure

### `tp.configure(**settings)`

Sets global defaults. Unknown names raise `TypeError`.

| Setting | Default | |
| - | - | - |
| `lm` | none | Model for every LM operator: a model string or a `tp.LM`. See [Choose a model](https://docs.tracepress.ai/models.md). |
| `max_concurrency` | `128` | LM calls in flight at once. |
| `request_timeout` | `30.0` | Seconds before a per-row or fold-step call is abandoned and retried. |
| `reduce_timeout` | `120.0` | The same, for full reduce and merge calls. |
| `timeout_retries` | `2` | Retries after a timeout. |
| `reduce_chunk_chars` | `120_000` | Prompt size above which a reduce is split into a tree of calls. |
| `prices` | built-in | `{model: (input, output)}` in USD per million tokens, added to the known prices. |

### `tp.LM(model, **options)`

A model built from the same strings as `lm=`, with options passed along to the provider, such as
`temperature`, `max_tokens`, `api_base` or `api_key`. Options you pass win over a gateway's own.
Use it anywhere a model string goes.

```python theme={null}
tp.LM("openrouter:openai/gpt-6-luna", temperature=0.0)
tp.LM("openai/my-model", api_base="http://localhost:8000/v1", api_key="local")
```

### `tp.last_run()`

Calls, tokens, cost, errors and time for the latest run, even one still going. `.status` is
`"running"`, `"completed"`, `"failed"` or `"cancelled"`.

## Sources

A source has one or more tables, as attributes (`src.steps`) or by name (`src.table("steps")`).
See [Load traces](https://docs.tracepress.ai/cookbooks/sources.md).

| Function | Reads | Tables (levels) |
| - | - | - |
| `tp.read.harbor(path, tasks=None, limit=None)` | A Harbor job, its `trials/` directory, or a directory of jobs. | `trials`, `steps`, `tool_calls`, `tests` (`dataset > task > trial > step`) |
| `tp.read.atif(path)` | ATIF trajectories: a file, directory, glob or list. | `trajectories`, `steps`, `tool_calls` (`trajectory > step`) |
| `tp.read.claude_code(path=None, project=None, limit=None, subagents=True, inherited=False)` | Claude Code or Agent SDK sessions, `~/.claude/projects` by default. | `sessions`, `steps`, `tool_calls` (`project > session > step`) |
| `tp.read.codex(path=None, project=None, limit=None)` | Codex CLI sessions, `~/.codex/sessions` by default. | same as Claude Code |
| `tp.read.otel(path)` | OTLP JSON files: a file, directory, glob or list. | `traces`, `spans`, `steps`, `tool_calls` (`trace > step`) |
| `tp.watch.otlp(port=4318, host="127.0.0.1", settle=2.0, idle_timeout=300.0)` | Live traces over OTLP/HTTP at `/v1/traces`. | same as `read.otel` |
| `tp.replay(source, speed=None, seed=0, drop_closes=0.0, shuffle_within=0, duplicates=0.0)` | A stored source played back as a stream, in timestamp order. `speed=30` is 30x real time. The other arguments inject faults for testing. | same as `source` |
| `tp.from_pandas(df, levels)` | A DataFrame; `levels` are the key columns, outermost first. | a single table |
| `tp.from_rows(rows)` | Rows you collected earlier. | a single table |

`tp.read.dspy` and `tp.read.chatgpt` are planned and raise `NotImplementedError` for now.

## Table

Every method returns a new table. LM methods take `instructions=`, `lm=` (overrides the
configured model), `module=` (default `dspy.Predict`) and
`on_error="skip"` (or `"raise"`).

### Row operators

| Method | |
| - | - |
| `filter(pred)` | Keeps rows where `pred(row)` is true. |
| `map(fn, columns=None)` | Adds or replaces columns with `fn(row) -> dict`. Pass `columns={name: type}` to keep schema checks. |
| `select(*columns)` | Keeps only these columns. |
| `explode(column, level=None, keep=())` | One row per item of a list column, one level deeper. |
| `join(other, on, how="left", columns=None, suffix=None)` | Adds the matching row's columns from `other`, matched `on` a key level or on columns. `how="inner"` drops unmatched rows. |
| `lm_map(sig)` | One LM call per row; outputs become columns. |
| `lm_filter(sig)` | Keeps rows where the signature's single bool output is true. |
| `lm_extract(sig, level=None, keep=())` | One row per item of the signature's single list output, one level deeper. |

### `group_by(*names)`

Groups by key levels or any other columns, and returns a grouped table with:

| Method | |
| - | - |
| `reduce(fn, columns)` | Plain-Python `fn(rows) -> dict` per group. `columns={name: type}` is required. |
| `lm_reduce(sig, emit="close", chunk_chars=None)` | One LM call per group. |
| `lm_fold(sig, init=None, emit="close")` | One LM call per row in key order, carrying the state named on both sides of the arrow. |

`group_by()` with no names treats the whole table as one group. `emit="update"` or
`emit=tp.every(n)` also emits provisional rows on live streams. See [Concepts](https://docs.tracepress.ai/concepts.md) for
how reduce inputs bind.

### Running

| Method | |
| - | - |
| `collect(max_concurrency=None, lineage=False)` | Runs the plan and returns final rows, sorted by key. `lineage=True` records inputs for `row.inputs()`. |
| `await acollect(...)` | `collect` inside an event loop, such as Jupyter. |
| `to_pandas()` | `collect` as a DataFrame. |
| `events()` | Async iterator over every output event: provisional rows, final rows and `tp.Closed`. |
| `tp.collect(*tables)` / `await tp.acollect(*tables)` | Runs several tables in one pass; shared upstream work runs once. |

### Tuning and what-if

| Method | |
| - | - |
| `optimize(labels, metric, budget=60, val_frac=0.3, seed=0, reflection_lm=None)` | Tunes this LM step's instructions with GEPA. See [Optimization](https://docs.tracepress.ai/cookbooks/optimize.md). |
| `instructions` | The step's current instructions. |
| `rerun(edit)` | The table as if some upstream rows had been different. |

## Row

| | |
| - | - |
| `row.<column>`, `row.get(name, default)` | A column, or a key level of the same name. |
| `row.key` | The hierarchical key, as `((level, id), ...)`. |
| `row.final`, `row.version` | `False` for provisional rows; the version goes up with each update. |
| `row.inputs()` | The rows this one was built from (needs `collect(lineage=True)`). |
| `row.to_dict()` | Columns and key levels as a dict. |

`tp.rows_to_pandas(rows)` turns a list of rows into a DataFrame.

## Server

### `tp.connect(address="localhost:7700", token=None)`

A client for a server started with [`tracepress serve`](https://docs.tracepress.ai/reference/cli). `token` defaults to
`$TRACEPRESS_TOKEN`.

| Method | |
| - | - |
| `stream(source, tables=None)` | Streams a source's events to the server in the background. `.wait()` blocks until a bounded source is sent; `.stop()` stops early. |
| `push(rows, table)` | Sends rows (or events such as `tp.Closed(prefix)`) into one table. |
| `source` | The server's stream, to build pipelines on. |
| `register(name, pipeline)` | Runs a pipeline on the server continuously. Registering a name again replaces it. |
| `unregister(name)` | Stops and removes a pipeline. |
| `pipelines()` | Registered pipelines with their status and rows so far. |
| `listen(name, from_start=False)` | Async iterator over a pipeline's events, each with `kind` (`"added"`, `"updated"` or `"closed"`) and `row`. |

## Built-in pipelines

`tp.pipelines.harbor` has the Terminal-Bench failure taxonomies. See
[Built-in pipelines](https://docs.tracepress.ai/pipelines.md).

## Next steps

> [card] [Concepts](https://docs.tracepress.ai/concepts.md)
>
> How the operators fit together.

> [card] [CLI](https://docs.tracepress.ai/reference/cli.md)
>
> The `tracepress serve` command.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.