JupyterLab extension to inspect Python Bytecode.
Try it onlineTry the extension in your browser with Binder:
Prerequisitesipykernel
or xeus-python
To install JupyterLab:
Installationconda install -c conda-forge jupyterlab
Featuresjupyter labextension install jupyterlab-python-bytecode
Avanced Settings Editor
to tweak some of the settingsSee CONTRIBUTING.md to know how to contribute and setup a development environment.
How it worksDisassembling the Python code is done by connecting to a kernel, and sending the following code for evaluation from the lab extension:
import dis
dis.dis(code_to_evaluate)
As mentioned in the documentation, there is not guarantee on the stability of the bytecode across Python versions:
ExampleBytecode is an implementation detail of the CPython interpreter. No guarantees are made that bytecode will not be added, removed, or changed between versions of Python. Use of this module should not be considered to work across Python VMs or Python releases.
For example, if the Python file contains the following lines:
import math
Â
print(math.pi)
The following code will be sent to the kernel for evaluation:
import dis
dis.dis("""
import math
Â
print(math.pi)
""")
Which will return (example for CPython 3.6.6):
Comparing versions of CPython  1           0 LOAD_CONST               0 (0)
              2 LOAD_CONST               1 (None)
              4 IMPORT_NAME              0 (math)
              6 STORE_NAME               0 (math)
Â
  3           8 LOAD_NAME                1 (print)
             10 LOAD_NAME                0 (math)
             12 LOAD_ATTR                2 (pi)
             14 CALL_FUNCTION            1
             16 POP_TOP
             18 LOAD_CONST               1 (None)
             20 RETURN_VALUE
If you have several versions of Python installed on your machine (let's say in different conda environments), you can use the extension to check how the bytecode might differ.
The following example illustrates the introduction of the new CALL_METHOD
opcode introduced in CPython 3.7:
Original example from Disassembling Python Bytecode, by Peter Goldsborough
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4