Skip to content

feat(scope): add claudescope-py Python client wrapping the CLI - #27

Merged
rylero merged 1 commit into
mainfrom
worktree-claudescope-python-wrapper
Jul 6, 2026
Merged

rylero merged 1 commit into
mainfrom
worktree-claudescope-python-wrapper

Conversation

@rylero

@rylero rylero commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds a python/ package (claudescope-py) wrapping the ClaudeScope CLI so users get session.query(spl) -> pandas.DataFrame instead of shelling out and hand-parsing JSON.
  • Wraps the CLI binary via subprocess (reuses its daemon auto-start logic in cli/client.go) rather than duplicating session/daemon lifecycle logic against the HTTP API directly — see python/README.md for the tradeoff.
  • Covers load/connect/sessions, query → DataFrame, query_multi (union mode → one tagged DataFrame with df.attrs["errors"]; comparison mode → dict[session_id, DataFrame | ClaudeScopeError]), plus get/range/find_bool/find_threshold/stats/set/disconnect.
  • Unwraps the CLI's double-encoded error payload (main.go's writeErrorAndExit wraps a failed daemon request's own JSON error body in another {error, code} envelope) so callers get a clean message/code instead of a raw JSON blob — found and fixed this while doing end-to-end verification.

Test plan

  • pytest (14 tests, mocked subprocess) — all pass
  • Built the Go binary from this branch and ran the wrapper end-to-end against a synthetic .wpilog: query, timechart, find_bool, stats, query_multi (union + comparison), and the error path (missing field) all verified against the real binary, not just mocks

🤖 Generated with Claude Code

Lets users go straight from a query to a pandas.DataFrame instead of
shelling out to the ClaudeScope CLI and hand-parsing JSON themselves.

    import claudescope as scope
    session = scope.load("/path/to/log.wpilog")
    df = session.query("stats avg(BatteryVoltage) by Subsystem")

Wraps the CLI binary via subprocess (reuses its daemon auto-start
logic) rather than talking to the daemon HTTP API directly. Covers
load/connect/sessions, query (-> DataFrame), query_multi (union ->
tagged DataFrame with attrs["errors"]; comparison -> dict of
DataFrame/ClaudeScopeError per session), and the remaining
get/range/find-bool/find-threshold/stats/set/disconnect commands.

Unwraps the CLI's double-encoded error payload (writeErrorAndExit
wraps a failed daemon request's own JSON error body in another
{error, code} envelope) so callers see a clean message/code instead
of a raw JSON blob.

Verified end-to-end against a real built binary and a synthetic
.wpilog (query, timechart, find-bool, stats, query_multi union and
comparison modes, and the error path).
@rylero
rylero marked this pull request as ready for review July 6, 2026 06:56
@rylero
rylero merged commit f3a6f5b into main Jul 6, 2026
1 check passed
@rylero
rylero deleted the worktree-claudescope-python-wrapper branch July 6, 2026 06:56
rylero added a commit that referenced this pull request Jul 6, 2026
…python client

SKILL.md hadn't been updated for #27 (claudescope-py) or #28
(--follow/search-fields), and this branch adds --format csv/parquet
on top -- the agent-facing guide was missing all four. Documents:
- search-fields command
- --format csv/parquet output for query/query-multi --union true
- query --follow true live streaming (NDJSON, incompatible with
  --format/--out)
- the claudescope-py Python client, recommended over --format for
  Python consumers since it builds a DataFrame directly

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
rylero added a commit that referenced this pull request Jul 6, 2026
* feat(scope): add --format csv to query/query-multi

CSV output lets query results feed pandas.read_csv() directly
without a JSON parsing round-trip. Columns are the union of all
row keys, sorted alphabetically with Timestamp pinned first for
determinism across heterogeneous rows (e.g. stats/timechart by
group). query-multi requires --union true since comparison mode
isn't row-shaped.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* feat(scope): add --format parquet, fix CSV bool dtype

Parquet preserves native bool/float64/string types and true nulls
for missing columns, unlike CSV which must stringify everything.
Column type per field is inferred from non-nil values (bool/float64/
string), falling back to a stringified UTF8 column on any mix so
the writer never errors on unexpected value shapes.

Also fix CSV output to write bools as "True"/"False" instead of
Go's lowercase "true"/"false" -- pandas.read_csv's C parser only
recognizes the capitalized form as boolean, otherwise the column
comes back as object dtype.

Adds github.com/parquet-go/parquet-go as a new dependency.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* docs(scope): update SKILL.md for csv/parquet, follow, search-fields, python client

SKILL.md hadn't been updated for #27 (claudescope-py) or #28
(--follow/search-fields), and this branch adds --format csv/parquet
on top -- the agent-facing guide was missing all four. Documents:
- search-fields command
- --format csv/parquet output for query/query-multi --union true
- query --follow true live streaming (NDJSON, incompatible with
  --format/--out)
- the claudescope-py Python client, recommended over --format for
  Python consumers since it builds a DataFrame directly

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* fix(scope): stop parquet writer from nulling falsy values

Found via end-to-end testing against a real .wpilog and pandas
(not just Go-side round-trip tests): rowsToParquet wrote rows via
GenericWriter's map/reflect path (w.Write([]map[string]any{...})),
whose isNullValue check (parquet-go's column_buffer_reflect.go)
treats any Go zero value -- false, 0.0, "" -- as equivalent to an
absent key for Optional columns. A real Enabled=false or a sensor
reading of exactly 0.0 was silently coming back as a Parquet null
(NaN/None in pandas), which is a correctness bug that would corrupt
real telemetry data on release.

Fix: build parquet.Row values manually with explicit definition
levels (1 = present, 0 = null) via schema.Lookup for each column's
index, bypassing the reflect path entirely. Verified against real
pandas: false/0.0/"" now round-trip as themselves, while genuinely
missing columns (e.g. an unmatched lookup join) still round-trip as
null. Added a regression test.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant