Directory Compare FCRS-1.0 /llms.txt
← Back to Directory

py-spy

$ py-spy Community Med Risk
Ben Frederickson · Code & DevOps · MIT · macos / linux / windows

py-spy profiles running Python processes out-of-process in Rust without code changes or restarting the target. Agents can capture bounded profiles with py-spy record --duration 10 --format speedscope -o profile.json or grab instantaneous stack traces with py-spy dump --pid <pid>.

FCRS-1.0 Score
78 /100
Good
Medium Confidence
Zero-Friction Install
brew install py-spy
CLI vs MCP Decision CLI Only

OS-level sampling profiler reading live Python process memory; cannot be replaced by a remote MCP tool.

Agent-Readiness Checklist

✓ JSON Output
— Field Filtering
✓ Non-Interactive
— Dry-Run
— Read-Only Mode
— NO_COLOR Clean
✓ Self-Describing
— Official SKILL.md

Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.

FCRS-1.0 6-Dimension Breakdown

Agent-Readiness 19 / 25

dump and bounded record --duration run non-interactively with --format speedscope / chrometrace JSON output, while py-spy top is a blocking TUI.

  • --format speedscope and --format chrometrace emit JSON files
  • py-spy top opens an interactive terminal UI
Trust & Safety 19 / 25

Read-only memory sampling avoids modifying the target process, though attaching by --pid requires elevated ptrace/root privileges on Linux and macOS.

  • Out-of-process sampling requires CAP_SYS_PTRACE or sudo on attach
Setup & Portability 13 / 15

Single compiled Rust binary available via brew, pip, and cargo on macOS, Linux, and Windows.

  • Prebuilt wheels and Homebrew formula across all 3 OSes
Utility & Efficiency 12 / 15

Safe for diagnosing live production Python bottlenecks with minimal overhead and native C-extension frame support (--native).

  • Zero-instrumentation sampling with --native and --subprocesses
Maintenance & Lineage 8 / 10

Widely adopted open-source profiler (benfred/py-spy) under MIT license.

  • Standard Python sampling profiler in production environments
Docs & Verifiability 7 / 10

Clear README and subcommand --help covering formats, flags, and container permissions.

  • Documented Docker SYS_PTRACE and OS caveats in README

Security, Auth & Guardrails

Auth Modes
No Auth
Credential Storage

No credentials required; reads target Python process memory via OS process_vm_readv / vm_read APIs.

Side Effects
Read-Only Local Write
Cost & Quotas

MIT open-source Rust/Python CLI; free.

Copyable Guardrail for CLAUDE.md / AGENTS.md
# py-spy Agent Rules
- Always pass `--duration <seconds>` on `py-spy record` and avoid `py-spy top` (which runs an interactive TUI).
- Use `--format speedscope` or `--format chrometrace` when machine-parseable JSON output is needed.
- Note that attaching to an existing `--pid` often requires `sudo` or `CAP_SYS_PTRACE`.

Agent-Ready Command Recipes

Safe Read-Only Queries

Dump current Python stack traces by PID
py-spy dump --pid 12345

Prints call stacks for all active threads in PID 12345 immediately without writing files.

Controlled Writes & Previews

Record a 10-second Speedscope JSON profile
py-spy record --duration 10 --format speedscope -o profile.json -- python app.py

Samples app.py for 10 seconds and writes structured Speedscope JSON profiling data to profile.json.

Strengths for Agents

  • + Attaches to live Python processes with virtually zero overhead and no code edits.
  • + Exports machine-readable speedscope and chrometrace JSON profiles via record --format.
  • + py-spy dump instantaneously reveals blocked or deadlocked threads.

Caveats & Pitfalls

  • ! py-spy top is an interactive TUI that blocks agent sessions.
  • ! Attaching to running PIDs typically fails in restricted sandboxes without sudo or SYS_PTRACE.

Tested Agent Hosts

Claude Code Codex CLI Gemini CLI