pyspy

Profile Python script CPU time with py-spy and output speedscope JSON.

383|92|Updated Apr 30, 2022
One-click install
npx skills add https://github.com/scverse/spatialdata --skill pyspy
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pyspy
Source: https://github.com/scverse/spatialdata/tree/main/.claude/skills/pyspy
Command: npx skills add https://github.com/scverse/spatialdata --skill pyspy

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It helps you identify which parts of your Python code consume the most CPU time so you can speed up slow scripts and optimize performance with evidence.

Core Features & Use Cases

  • Execution time profiling with py-spy: Capture a CPU-time profile for a target Python script.
  • Speedscope visualization: Open the recorded profile in a browser-based viewer to inspect call paths and hotspots.
  • CPU vs GIL time control: Use options like recording only GIL-held time for Python-level CPU profiling or include deeper native activity by adjusting flags.

Use when you need to debug performance regressions, compare versions, or confirm whether the slowness comes from Python vs extension/native work.

Quick Start

Profile your script by running the profiling environment command for pyspy with your script path, producing a speedscope JSON profile you can open afterward.

Frequently Asked Questions about pyspy

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I find bottlenecks in a slow Python script?

Python profiling with py-spy captures CPU-time execution data, recording call stacks into a speedscope JSON file to visually identify which code paths consume the most execution time.

Can I profile only GIL-held time on macOS to debug Python-level performance?

Yes, py-spy profiling supports recording only GIL-held time, isolating Python-level CPU activity from native extension work, which specifically addresses macOS performance debugging scenarios.

How do I visualize CPU profiling results for interactive hotspot analysis?

Profiling results are written to a profile.speedscope.json file, which launches speedscope in a browser-based viewer to interactively inspect recorded call stacks and pinpoint hotspots.

What is the best way to distinguish Python code slowness from native extension overhead?

CPU-time profiling with py-spy distinguishes Python-level execution from native work by adjusting recording flags, confirming whether slowness originates from Python code or extension activity.

Do I need a specific environment to run CPU-time benchmarking with py-spy?

Yes, you must run py-spy profiling within the specified pixi profiling environment to properly capture CPU-time profiles and generate the speedscope visualization output.

Why does my Python performance debugging require writing a speedscope JSON file?

Writing a profile.speedscope.json file captures the complete recorded call stacks from your Python script execution, enabling speedscope to render interactive visualizations for hotspot identification.