Visualize Python algorithms step by step
PyTrace is a free algorithm visualizer for Python. Paste your solution to a LeetCode-style problem, fill in the inputs and press Run: PyTrace executes your code line by line and animates what happens at every step. You see arrays with their index pointers (i, j, left, right…), matrices and grids, hash maps, linked lists, binary trees, graphs, local variables and the call stack, and you can play, pause and scrub back and forth through the execution.
It is the tool I wanted while studying for coding interviews: seeing how two pointers close in, how a sliding window grows and shrinks, how a tree gets traversed or why a recursive function never stops is much easier than tracing it in your head or filling your code with prints.
What it visualizes
- Lists, tuples, strings and
dequeas arrays of cells, with index variables drawn as pointers - Lists of lists as 2D grids and matrices
dict,defaultdict,Counteras key → value tables, andsetas chips- Linked lists (
ListNodeor anything withnext,prev,random) - Binary trees (
TreeNodeor anything withleft/right) - N-ary trees and graphs (objects with
children/neighbors) - The call stack, recursion included, and the comparisons evaluated on the current line
Runs entirely in your browser
PyTrace uses Pyodide, CPython compiled to WebAssembly. There is no server: your code runs on your own machine and never leaves it. It is free and open source.
Made for LeetCode practice
- Paste a
class Solutionas-is: PyTrace detects the method and its parameters and creates input fields - Inputs in LeetCode notation:
[1,2,3],[3,9,20,null,null,15,7] - Design problems such as
LRUCacheorMinStackwith operation lists - Several test cases, each with an optional expected value
ListNode,TreeNode,collections,heapq,bisect… preloaded- Share your solution with a link (🔗 Share)
Examples
FAQ
Does my code leave my computer?
No. PyTrace runs CPython compiled to WebAssembly (Pyodide) inside your browser tab. There is no server, and your code, test cases and layout are only saved in your browser's localStorage.
Can I paste my LeetCode solution as-is?
Yes. Write it in the usual class Solution format (plain functions and scripts work too). PyTrace detects the method parameters and creates input fields. ListNode and TreeNode inputs use LeetCode notation such as [1,2,3] or [3,9,20,null,null,15,7], and common imports like collections, heapq and bisect are preloaded.
Are there limits?
Each run records up to 5,000 steps, and visualizations are capped (arrays up to 80 cells, matrices up to 40×40). It is meant for small inputs, not for measuring performance. Threads, subprocesses and sockets are not available.
Is PyTrace free?
Yes. PyTrace is free, open source and needs no sign-up.
Found a bug or have an idea? Open an issue on GitHub.