What it does
Scalene is a profiler for Python programs. It uses sampling rather than instrumentation, and reports time and memory down to individual lines and functions. It separates time spent in Python from time in native library code, shows system time to help find I/O bottlenecks, reports GPU time on NVIDIA hardware, flags likely memory leaks, and shows copy volume between Python and libraries such as numpy. It also attributes wait time to the exact line where an async coroutine is suspended, and can show call stacks, memory flame charts and a timeline that combine Python and native frames. For optimization help, you choose an AI provider in the interface (Amazon Bedrock, Microsoft Azure, OpenAI, or local models through Ollama), enter credentials if needed, and click a lightning bolt beside a line or region to get a proposed rewrite. Results can be viewed in a browser interface that works fully offline, in the terminal, or inside a Visual Studio Code extension. Install it with pip or conda and run it with scalene run on a script. The project is released under the Apache 2.0 license.
Capabilities
- Line-level and function-level CPU, GPU and memory profiling
- Splits Python time from native-code time
- Likely memory leak detection and copy-volume reporting
- AI-proposed optimizations through OpenAI, Amazon Bedrock, Azure or local Ollama models
- Offline browser interface, terminal view and VS Code extension
- Async await-time profiling and combined Python and native stack views
When to use it
- A Python program is slow or uses too much memory and you need to find the exact lines responsible
- You want an AI model to suggest rewrites for the hottest lines of code
- You need profiling that runs without a network connection