jupyter-python-tutor 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,151 @@
1
+ Metadata-Version: 2.4
2
+ Name: jupyter-python-tutor
3
+ Version: 0.2.0
4
+ Summary: Python Tutor-style step-by-step code visualization for JupyterLab 4.x and Notebook 7
5
+ Author: dive4dec
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/dive4dec/jupyter-python-tutor
8
+ Project-URL: Repository, https://github.com/dive4dec/jupyter-python-tutor
9
+ Project-URL: Issues, https://github.com/dive4dec/jupyter-python-tutor/issues
10
+ Project-URL: Changelog, https://github.com/dive4dec/jupyter-python-tutor/blob/main/CHANGELOG.md
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: ipython>=8.0
15
+ Provides-Extra: dev
16
+ Requires-Dist: pytest; extra == "dev"
17
+ Requires-Dist: build; extra == "dev"
18
+ Requires-Dist: twine; extra == "dev"
19
+ Dynamic: license-file
20
+
21
+ # jupyter-python-tutor
22
+
23
+ Python Tutor–style step-by-step code visualization directly inside JupyterLab 4.x and Notebook 7 cells.
24
+
25
+ ## Quick Start
26
+
27
+ ```bash
28
+ pip install jupyter-python-tutor
29
+ ```
30
+
31
+ In a Jupyter cell:
32
+
33
+ ```python
34
+ %load_ext jupyter_python_tutor
35
+ ```
36
+
37
+ Then use the `%%tutor` cell magic:
38
+
39
+ ```python
40
+ %%tutor
41
+ x = 3
42
+ y = x + 4
43
+ print(y)
44
+ ```
45
+
46
+ An interactive trace appears below the cell — drag the slider to navigate
47
+ through execution, see variable values change at each line, with SVG arrows
48
+ from frame variables to heap objects (like [Python Tutor](https://pythontutor.com)).
49
+
50
+ ## Features
51
+
52
+ - **Interactive slider navigation** — drag the slider (or use ◀ ▶ buttons / ← → arrow keys) to scrub through execution steps
53
+ - **SVG pointer arrows** — arrows from frame variables to heap objects, like OPT_Mentor / Python Tutor
54
+ - **Single-step view** — only the current step is shown (not all steps stacked)
55
+ - **Call stack visualization** — global frame + local frames with line numbers
56
+ - **Heap objects** — lists, dicts, class instances, functions, and other objects shown as boxes with arrows pointing to them
57
+ - **Resizable columns** — drag the vertical dividers between code / variables / objects to resize; double-click a divider to collapse/expand
58
+ - **Auto-height** — iframe height follows the tallest column content (no fixed height, no internal scroll)
59
+ - **AST-based variable filtering** — only variables used by the traced code are shown (no IPython internals, no contamination from other cells)
60
+ - **stdout capture** — `print()` output is displayed per step
61
+ - **functools.wraps-safe** — functions show their true name (`__code__.co_name`), not the wrapper's `__name__`
62
+ - **Trusted notebook support** — renders fully (with JS, CSS, arrows) in trusted notebooks; `jupyter trust notebook.ipynb` after execution
63
+ - **Works with Notebook 7** — compatible with the new Jupyter Notebook 7 (JupyterLab-based)
64
+ - **Pure Python** — no compiled extensions, works in CPython 3.8+
65
+
66
+ ## Options
67
+
68
+ ```
69
+ %%tutor --max-steps 1000 # Limit trace steps (default: 5000)
70
+ %%tutor --raw # Output trace as JSON instead of HTML
71
+ %%tutor --height 400 # Set minimum widget height (default: 500)
72
+ ```
73
+
74
+ ## Examples
75
+
76
+ ### Loops
77
+
78
+ ```python
79
+ %%tutor
80
+ total = 0
81
+ for i in range(5):
82
+ total += i
83
+ print(f"Sum: {total}")
84
+ ```
85
+
86
+ ### Functions with recursion
87
+
88
+ ```python
89
+ %%tutor
90
+ def factorial(n):
91
+ if n <= 1:
92
+ return 1
93
+ return n * factorial(n - 1)
94
+
95
+ result = factorial(4)
96
+ print(result)
97
+ ```
98
+
99
+ ### Classes and inheritance
100
+
101
+ ```python
102
+ %%tutor
103
+ class Animal:
104
+ def __init__(self, name):
105
+ self.name = name
106
+ def speak(self):
107
+ return f"{self.name} says hello"
108
+
109
+ class Dog(Animal):
110
+ def speak(self):
111
+ return f"{self.name} barks"
112
+
113
+ d = Dog("Rex")
114
+ print(d.speak())
115
+ ```
116
+
117
+ ## How It Works
118
+
119
+ 1. **Tracing**: The `%%tutor` magic compiles the cell code and executes it under
120
+ `sys.settrace()`. At each line/call/return event, a snapshot of all local and
121
+ global variables is captured. AST analysis (`ast.parse`) extracts the set of
122
+ names the traced code touches, so only code-relevant variables are shown
123
+ (filtering out IPython internals and variables from other cells).
124
+
125
+ 2. **Rendering**: The trace steps are rendered as a complete HTML page inside
126
+ an `<iframe srcdoc="...">`. This bypasses JupyterLab 4's HTML sanitizer
127
+ (which strips `<script>`, `<style>`, `<button>`, `<input>`, etc. from
128
+ untrusted output). In trusted notebooks, the iframe renders with full
129
+ CSS + JavaScript — enabling slider navigation, SVG arrows, draggable
130
+ dividers, and auto-height.
131
+
132
+ 3. **Arrows**: SVG paths are computed at render time from the bounding boxes
133
+ of pointer boxes (in frame variables) to heap objects. Arrows redraw on
134
+ slider navigation, column resize, and window resize.
135
+
136
+ 4. **JupyterLab 4 compatibility**: JupyterLab 4's HTML sanitizer (DOMPurify)
137
+ strips JavaScript and external URLs from untrusted notebooks. The iframe
138
+ `srcdoc` approach bypasses this entirely in trusted notebooks. Run
139
+ `jupyter trust your_notebook.ipynb` after executing cells with `%%tutor`
140
+ to ensure the visualization renders correctly.
141
+
142
+ ## Limitations
143
+
144
+ - **Trusted notebooks required** for full rendering (arrows, slider, dividers).
145
+ Untrusted notebooks will show a stripped-down version.
146
+ - `sys.settrace()` adds overhead — very long loops will be slow; use `--max-steps` to limit
147
+ - Threads are not traced (only the main thread)
148
+
149
+ ## License
150
+
151
+ MIT
@@ -0,0 +1,9 @@
1
+ jupyter_python_tutor/__init__.py,sha256=wUrbX9qkGSp-sJjUEF5bvevIBpWB2Mx7ixEzyg4_VFI,373
2
+ jupyter_python_tutor/magics.py,sha256=5U-IIVMqRgiBKiVDMPh5kwuo3wovZVj__M3W7bJ3yWc,3718
3
+ jupyter_python_tutor/renderer.py,sha256=GOnPKKWN-EPnawk2BsF26ONfE_zEzRIApa5hGv6pPds,33920
4
+ jupyter_python_tutor/tracer.py,sha256=LXe2Kwk8fCi5AOYAsDenEMcehJ4Uux0y6aq5U82-FQk,23271
5
+ jupyter_python_tutor-0.2.0.dist-info/licenses/LICENSE,sha256=l2oOhGEO85UPMUiHAgK3C4t3OP8J2KMTQ5FuKFwSVmg,1065
6
+ jupyter_python_tutor-0.2.0.dist-info/METADATA,sha256=R9NdMV-YAjnFuakzTpIJ7FWrtxSHLPwgwHRv62qgZ0A,5268
7
+ jupyter_python_tutor-0.2.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
8
+ jupyter_python_tutor-0.2.0.dist-info/top_level.txt,sha256=e4mne6ggtOeo_pmq5fKZ6crLqXsUq-d0MR83Ir9JvGQ,21
9
+ jupyter_python_tutor-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (83.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dive4dec
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ jupyter_python_tutor