py-spy
$ py-spy Community Med Riskpy-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>.
brew install py-spy OS-level sampling profiler reading live Python process memory; cannot be replaced by a remote MCP tool.
Agent-Readiness Checklist
Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.
FCRS-1.0 6-Dimension Breakdown
dump and bounded record --duration run non-interactively with --format speedscope / chrometrace JSON output, while py-spy top is a blocking TUI.
--format speedscopeand--format chrometraceemit JSON filespy-spy topopens an interactive terminal UI
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_PTRACEorsudoon attach
Single compiled Rust binary available via brew, pip, and cargo on macOS, Linux, and Windows.
- Prebuilt wheels and Homebrew formula across all 3 OSes
Safe for diagnosing live production Python bottlenecks with minimal overhead and native C-extension frame support (--native).
- Zero-instrumentation sampling with
--nativeand--subprocesses
Widely adopted open-source profiler (benfred/py-spy) under MIT license.
- Standard Python sampling profiler in production environments
Clear README and subcommand --help covering formats, flags, and container permissions.
- Documented Docker
SYS_PTRACEand OS caveats in README
Security, Auth & Guardrails
No credentials required; reads target Python process memory via OS process_vm_readv / vm_read APIs.
MIT open-source Rust/Python CLI; free.
# 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
py-spy dump --pid 12345
Prints call stacks for all active threads in PID 12345 immediately without writing files.
Controlled Writes & Previews
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
speedscopeandchrometraceJSON profiles viarecord --format. - +
py-spy dumpinstantaneously reveals blocked or deadlocked threads.
Caveats & Pitfalls
- !
py-spy topis an interactive TUI that blocks agent sessions. - ! Attaching to running PIDs typically fails in restricted sandboxes without
sudoorSYS_PTRACE.