Metadata-Version: 2.5
Name: wizardflow
Version: 0.10.0
Summary: Python SDK for recording agent flows into the WizardFlow / AgentTrace file format.
Project-URL: Homepage, https://getwizardflow.com
Project-URL: Documentation, https://github.com/lkleonk/wizardflow/tree/main/sdk/python/docs
Project-URL: Source, https://github.com/lkleonk/wizardflow
Project-URL: Issues, https://github.com/lkleonk/wizardflow/issues
Author: Leon Koch
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: agents,langgraph,llm,observability,tracing
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.9
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == 'dev'
Description-Content-Type: text/markdown

# WizardFlow Python SDK

**A lightweight recorder for Python agents.** WizardFlow turns an agent run
into a portable WizardFlow JSONL file that you can replay as an interactive
graph, inspect with ordinary tools, or attach to a bug report.

Drop the file into [getwizardflow.com](https://getwizardflow.com) and it is
processed entirely in the browser, so nothing is uploaded. You can also replay it
locally with `wizardflow replay`, or collect many runs, and the traces and logs
of any app with OpenTelemetry, in a local dashboard: `wizardflow dashboard`.

![WizardFlow replaying an agent run](https://raw.githubusercontent.com/lkleonk/wizardflow/main/sdk/python/assets/demo.gif)

▶ **[Watch this run replay](https://getwizardflow.com/?example=doctor-consultation)**

## Why WizardFlow?

- **The trace is a file.** Commit, diff, grep, archive, or share it without an
  observability account.
- **Replay it anywhere.** Use the bundled local viewer or the fully client-side
  hosted viewer.
- **Zero runtime dependencies.** The package is pure Python and requires no
  daemon or framework. Recording, OTLP export of a finished run, and the local
  dashboard with its OTLP receiver all use only the standard library (see
  [Dependencies](#dependencies)).
- **Explicit by design.** Your code chooses which node executions and values
  enter the trace.
- **OpenTelemetry is optional.** The same node executions can also be projected
  to OTLP-compatible observability backends.

## Install

```bash
pip install wizardflow
```

### Dependencies

None. Recording, replay, Markdown/HTML/JSON export, the local dashboard with
its database and OTLP receiver, and sending to an OTLP endpoint, live while
recording or a finished run later, all use only the Python standard library.
WizardFlow installs anywhere and never pins a version your app also uses.

The OpenTelemetry packages only come in when you want WizardFlow's spans inside
your app's own traces:

| Live export (`init(otel=True)`) | Needs |
| --- | --- |
| Straight to an endpoint (`otel_endpoint=...`), e.g. to watch runs arrive in `wizardflow dashboard` | Nothing extra |
| Same, joined to your app's own traces | `opentelemetry-sdk` and `opentelemetry-exporter-otlp-proto-http` |
| Into your app's own tracing (no `otel_endpoint`) | `opentelemetry-api`, which an app with OpenTelemetry already has |

With an endpoint, WizardFlow uses the OpenTelemetry SDK when it is installed and
its own sender otherwise; `otel_exporter` picks one explicitly. See the
[OpenTelemetry guide](https://github.com/lkleonk/wizardflow/blob/main/sdk/python/docs/opentelemetry.md#installation).

## Quickstart

```python
import uuid

import wizardflow

trace = wizardflow.init(
    output_dir="traces",
    file_prefix="run",
    nodes=["generator"],
)

message_id = str(uuid.uuid4())
input_value = ...

with trace.node(message_id, "generator") as node:
    node.log_input(input_value)
    output_value = ...
    node.log_output(output_value)

trace_path = trace.end_message(message_id)
print(trace_path)
```

`trace.node(...)` records the node's execution interval. `log_input()` and
`log_output()` preserve their JSON-compatible values in the trace, and
`end_message()` appends the completed message to JSONL. There is no separate
`save()` call.

Recording mistakes such as an unknown node id are logged as warnings rather
than raised into your app; pass `on_error="raise"` to make them raise (handy in
tests). Pass `enabled=False`, or set `WIZARDFLOW_ENABLED=false`, to turn tracing
off while keeping the same API. See
[docs/recording.md](https://github.com/lkleonk/wizardflow/blob/main/sdk/python/docs/recording.md#error-handling-on_error).

Drop `trace_path` into [getwizardflow.com](https://getwizardflow.com), or open
it locally:

```bash
wizardflow replay traces/run__<timestamp>.jsonl
```

The module-level style remains available for applications that use one default
trace:

```python
wizardflow.init(nodes=["generator"])

with wizardflow.node("msg-1", "generator") as node:
    node.log_input(input_value)
    node.log_output(output_value)

wizardflow.end_message("msg-1")
```

## Local dashboard

For more than one run, `wizardflow dashboard` keeps your runs and any
OpenTelemetry traces in a local SQLite database: a span waterfall with the
graph beside it, GenAI messages and token counts, and a receiver on
`localhost:4318` that apps with OpenTelemetry can send to directly.

```bash
wizardflow dashboard run.jsonl   # import a run, then open the dashboard
```

![The WizardFlow dashboard: a span waterfall, the graph, and the span inspector](https://raw.githubusercontent.com/lkleonk/wizardflow/main/sdk/python/assets/dashboard.png)

See the [dashboard guide](https://github.com/lkleonk/wizardflow/blob/main/sdk/python/docs/otel-dashboard.md).

## Optional OpenTelemetry export

Enable OTLP trace export while retaining JSONL as the portable source of
truth. Sending to an endpoint needs no extra packages; to have the spans join
your app's own OpenTelemetry traces, install the OTel SDK
(see [Dependencies](#dependencies)):

```python
trace = wizardflow.init(
    nodes=["generator"],
    name="my-agent",
    otel=True,
    otel_endpoint="http://localhost:4318/v1/traces",
    otel_workflow_name="answer",
)

with trace.workflow() as run:               # one workflow = one OTel trace
    run.set_info(otel_attributes={"session.id": chat_id})
    with run.node("generator", kind="llm") as node:
        node.log_input(input_value)
        node.log_output(output_value)

trace.close_otel()
```

`otel_attributes` sets exact keys on the workflow's root span. For example,
`session.id` groups traces into Phoenix sessions, and `langfuse.session.id`
into Langfuse sessions.

Generic logs can optionally choose an exact application-owned span attribute
without changing their JSONL/UI label:

```python
node.log("quality", 0.92, otel_attribute="app.response.quality")
```

Content export is enabled by default when OTel export is enabled, with
`otel_include_content=False` and CLI `--no-include-content` available when the
receiver should only get metadata. See the
[OpenTelemetry guide](https://github.com/lkleonk/wizardflow/blob/main/sdk/python/docs/opentelemetry.md)
for provider ownership, GenAI mappings, content controls, graph events, and
independent JSONL/OTel lifecycles. Existing artifacts can be exported later,
without any OTel packages:

```bash
wizardflow otel export run.jsonl --endpoint http://localhost:4318/v1/traces
```

## LangGraph topology

WizardFlow can read nodes and edges from a compiled LangGraph application
without importing LangGraph itself:

```python
trace = wizardflow.init_from_langgraph(
    compiled_app,
    output_dir="traces",
    file_prefix="run",
)
```

Runtime recording then uses the same `trace.node(...)` API. Extraction is
duck-typed through `app.get_graph()`.

## Documentation

- **[Recording agent runs](https://github.com/lkleonk/wizardflow/blob/main/sdk/python/docs/recording.md)**
  — messages, node scopes, semantic records, generic logs, kinds, output
  selection, multiple clients, and reinitialization.
- **[OpenTelemetry export](https://github.com/lkleonk/wizardflow/blob/main/sdk/python/docs/opentelemetry.md)**
  — OTLP setup, provider ownership, GenAI mappings, privacy controls, graph
  events, offline JSONL export, and cleanup.
- **[WizardFlow JSONL format](https://github.com/lkleonk/wizardflow/blob/main/sdk/python/docs/jsonl-file-format.md)**
  — record shapes, semantic fields, compatibility, and rotation.
- **[CLI and local viewer](https://github.com/lkleonk/wizardflow/blob/main/sdk/python/docs/cli.md)**
  — every command: live local replay, Markdown, HTML, and JSON export, the
  dashboard, and database import.
- **[OTel dashboard](https://github.com/lkleonk/wizardflow/blob/main/sdk/python/docs/otel-dashboard.md)**
  — import runs and OTLP JSON or receive OTLP live into a local database,
  browse projects, traces, and logs, open graph replay, and map attributes.

## CLI at a glance

```bash
# Replay: one run file, nothing stored
wizardflow replay run.jsonl            # interactive local replay
wizardflow replay --latest traces/     # newest run in a directory
wizardflow md run.jsonl -o run.md      # Markdown export
wizardflow html run.jsonl -o run.html
wizardflow json run.jsonl -o run.json

# Dashboard: all your runs and OpenTelemetry data in a local database
wizardflow dashboard                   # open it, receiving OTLP on :4318
wizardflow dashboard run.jsonl         # import a run (or OTLP JSON), then open it
wizardflow db import run.jsonl         # import without opening
```

The replay commands read both WizardFlow JSONL and the single-document JSON form. See
the [CLI guide](https://github.com/lkleonk/wizardflow/blob/main/sdk/python/docs/cli.md)
for flags, live-trace behavior, and rotated-part navigation.

## Examples

Runnable examples live in
[`examples/`](https://github.com/lkleonk/wizardflow/tree/main/sdk/python/examples):

- `quickstart.py` records a small linear flow.
- `multibranch.py` records two messages that take different graph branches.

## Development

See
[CONTRIBUTING.md](https://github.com/lkleonk/wizardflow/blob/main/sdk/python/CONTRIBUTING.md)
for local tests and maintainer workflows.
