xdis is a Python library that provides a cross-version byte-code disassembler and marshal routines. It enables the inspection and manipulation of Python bytecode across a wide range of Python versions, from 1.0 up to 3.15+. The current version is 6.3.0, and it maintains an active release cadence, frequently updating with support for new Python versions and their respective bytecode changes.
pip install xdisVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `xdis.std.Bytecode` as a drop-in replacement for the standard library's `dis.Bytecode` to inspect a Python function's bytecode. While `xdis` excels at disassembling bytecode from *different* Python versions, this example focuses on its core disassembler functionality. For advanced cross-version loading from `.pyc` files, users should refer to `xdis.load` functions.
Review the `pydisasm -h` output and `xdis` documentation for updated API calls and format options. Adjust programmatic calls to `xdis` functions to match the new API.
For Python < 3.11, navigate to the `xdis` GitHub releases page and download the appropriate `xdis_X-x.y.z.tar.gz` or `.whl` file corresponding to your exact Python interpreter version. Install it manually using `pip install <downloaded_file>`. Ensure the Python environment you are installing into matches the target version of the `xdis` distribution.
Upgrade to `xdis` version 6.1.7 or newer to ensure correct `MAKE_FUNCTION` formatting and improved marshalling routines for Python 3.11+ bytecode.
Upgrade to `xdis` version 6.1.7 or newer to benefit from the performance fix for Python 3.11+ exception handling.
If bytecode manipulation for execution is required, proceed with caution and thorough testing. Recognize that `xdis` is primarily an analysis tool. Direct re-execution of `xasm`-generated bytecode might require deeper understanding of Python's internal code object structure beyond what basic disassembly/assembly provides. Consider `uncompyle6` for dekompilation to source if re-execution is the goal.
Ensure `xdis` is up-to-date (current version is 6.3.0). If you are processing bytecode from an older or very new Python version, verify that your installed `xdis` version explicitly supports that target Python version. For installations on Python < 3.11, ensure you followed the specific installation instructions for pre-built wheels/tarballs. If using `uncompyle6`, ensure both `uncompyle6` and `xdis` are the latest compatible versions.
The primary purpose of `xdis` is analysis, not necessarily perfect round-trip bytecode editing and re-execution. If you encounter this, understand that direct bytecode manipulation for execution can be very fragile. Verify the `xasm` project's documentation and current status for any known limitations or specific usage patterns to ensure executable output. Consider higher-level tools like `uncompyle6` for dekompilation if source code re-generation is the goal for execution.
Upgrade `xdis` to version 6.1.7 or newer to get the latest fixes and improvements for Python 3.11+ bytecode analysis. This ensures that the disassembly accurately reflects the behavior of newer Python interpreters.