{"id":1877,"library":"snakeviz","title":"SnakeViz","description":"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.","status":"active","version":"2.2.2","language":"en","source_language":"en","source_url":"https://github.com/jiffyclub/snakeviz","tags":["profiling","performance","visualization","cprofile","jupyter","ipython"],"install":[{"cmd":"pip install snakeviz","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Core profiling module whose output SnakeViz visualizes. It is a built-in Python module.","package":"cProfile","optional":false},{"reason":"Required for using the line and cell magics within Jupyter notebooks or IPython environments.","package":"IPython","optional":true}],"imports":[{"note":"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`).","symbol":"Command Line","correct":"snakeviz program.prof"},{"note":"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.","wrong":"import snakeviz","symbol":"IPython Magic","correct":"%load_ext snakeviz\n%snakeviz my_function()"}],"quickstart":{"code":"# 1. Profile your Python script using cProfile\nimport cProfile\nimport time\n\ndef waste_time():\n    sum(range(1000000))\n\ndef main():\n    for _ in range(5):\n        waste_time()\n\ncProfile.runctx('main()', globals(), locals(), 'output.prof')\n\n# 2. Open the profile in SnakeViz from your terminal\n#    (Run this in your shell, not in Python directly)\n# !snakeviz output.prof","lang":"python","description":"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."},"warnings":[{"fix":"Always use `cProfile` for generating profile data (e.g., `python -m cProfile -o output.prof my_script.py`).","message":"SnakeViz is primarily designed to work with profile data generated by Python's `cProfile` module. It does not support output from the older `profile` module.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"For 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"`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.","severity":"gotcha","affected_versions":"All versions"},{"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`.","message":"Official 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+.","severity":"breaking","affected_versions":"2.2.0 and later"},{"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.","message":"When 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}