Registry / observability / snakeviz

snakeviz

JSON →
library2.2.2pypypi✓ verified 23d ago

SnakeViz is a web-based viewer for Python profiler output, specifically designed for data generated by the `cProfile` module. It provides interactive graphical visualizations (icicle and sunburst charts) to help identify performance bottlenecks in Python code. The current version is 2.2.2, with releases occurring periodically to add features and address compatibility.

pip install snakeviz
INSTALL
IMPORT
SIG · SNAKEVIZ
S
snakeviz
observabilitypythonv2.2.2
Install
1.8s avg
Import
Disk
20MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.2.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 21.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.8s · import 0.000s · 22MB
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Command Line
snakeviz program.prof
SnakeViz is primarily used as a command-line tool to visualize a profile file (e.g., generated by `python -m cProfile -o program.prof my_script.py`).
IPython Magic
%load_ext snakeviz %snakeviz my_function()
import snakeviz
While `snakeviz` is a Python package, its core visualization functionality is invoked via a command-line executable or IPython magics, not typically by direct Python `import` statements for user-facing visualization functions. Attempting `import snakeviz` for visualization is not the standard use case.

This quickstart demonstrates how to profile a Python function using the built-in `cProfile` module and then visualize the generated profile data with SnakeViz from the command line. For Jupyter/IPython, use the `%snakeviz` magic after loading the extension.

# 1. Profile your Python script using cProfile import cProfile import time def waste_time(): sum(range(1000000)) def main(): for _ in range(5): waste_time() cProfile.runctx('main()', globals(), locals(), 'output.prof') # 2. Open the profile in SnakeViz from your terminal # (Run this in your shell, not in Python directly) # !snakeviz output.prof
snakeviz --version
Debug
Known issues
gotchaSnakeViz is primarily designed to work with profile data generated by Python's `cProfile` module. It does not support output from the older `profile` module.
fix
Always use `cProfile` for generating profile data (e.g., `python -m cProfile -o output.prof my_script.py`).
affects: All versions
gotchaFor very large or complex profile files, SnakeViz may struggle to create a visualization, sometimes displaying an error. This is due to the complexity of rendering an extremely large call tree.
fix
To mitigate this, try increasing the 'cutoff' value, reducing the 'depth' of the visualization, or profile a smaller, more focused subsection of your code. You can also manually navigate the stats table if the visualization fails.
affects: All versions
gotcha`cProfile`'s data format does not always allow a perfect reconstruction of the exact call stack and time spent, especially when the same function is called multiple times from different parts of the code. This can sometimes lead to slightly counter-intuitive visualizations.
fix
Be aware of this limitation when interpreting results, particularly with highly recursive or complex call patterns. Focus on the overall time distribution and major bottlenecks rather than micro-analyzing every single call path.
affects: All versions
breakingOfficial support for Python 2.7 has been dropped. While older versions (v2.1.2 and earlier) might still function, newer versions (2.2.0+) are built for Python 3.9+.
fix
Upgrade your Python environment to 3.9 or newer to ensure compatibility and receive updates. If Python 2.7 is strictly required, pin SnakeViz to a version `<=2.1.2`.
affects: 2.2.0 and later
gotchaWhen running SnakeViz via IPython magics outside of a Jupyter Notebook environment (e.g., in a terminal IPython session), the visualization will open in a new browser tab by default. Within Jupyter, it typically embeds in the notebook.
fix
Use the `--new-tab` or `-t` option with `%snakeviz` magic if you prefer to always open in a new tab, even in Jupyter. If working offline, save a profile file and use the command-line interface as IPython magics require internet access.
affects: All versions
Upgrade
Version history
2.2.2latest on PyPI · released Nov 9, 2024
Audit
Dependencies
cProfilerequiredCore profiling module whose output SnakeViz visualizes. It is a built-in Python module.
IPythonoptionalRequired for using the line and cell magics within Jupyter notebooks or IPython environments.
Agent activity
24 hits · last 30 days
node
18
OpenAI (training)
2
Resources
snakeviz — pip install snakeviz · libregistry