Skip to main content

Drop-in replacement for stdlib dis with human-friendly instruction descriptions

Project description

friendly-dis

A drop-in replacement for Python's dis module that adds human-friendly descriptions to every bytecode instruction.

Installation

pip install friendly-dis

Usage

As a library

import friendly_dis

# Disassemble a string of source code
friendly_dis.dis("x = 1; print(x)")

# Disassemble a function
def example(a, b):
    return a + b

friendly_dis.dis(example)

# Disassemble a code object
code = compile("x = 1", "<test>", "exec")
friendly_dis.disassemble(code)

As a CLI

# Disassemble a file
python -m friendly_dis script.py

# Or via the entry point
friendly-dis script.py

# Disassemble from stdin
echo "x = 1" | python -m friendly_dis

Example output

  0           RESUME                   0         # Internal: resume execution of a code object

  1           LOAD_SMALL_INT           1         # Load small integer 1 onto the stack
              STORE_NAME               0 (x)     # Store top of stack into name 'x'
              LOAD_NAME                1 (print)  # Load name 'print' onto the stack
              PUSH_NULL                          # Push a NULL onto the stack
              LOAD_NAME                0 (x)     # Load name 'x' onto the stack
              CALL                     1         # Call function with 1 argument
              POP_TOP                            # Remove the top of stack
              LOAD_CONST               1 (None)  # Load constant None onto the stack
              RETURN_VALUE                       # Return the top of stack to the caller

API

The module provides the same interface as dis:

  • dis(x, *, file=None, depth=None, show_caches=False, adaptive=False) — Disassemble classes, methods, functions, code objects, or source strings.
  • disassemble(co, lasti=-1, *, file=None, show_caches=False, adaptive=False) — Disassemble a code object.
  • distb(tb=None, *, file=None, show_caches=False, adaptive=False) — Disassemble a traceback.
  • describe(opname, arg, argval, argrepr) — Get a human-friendly description for any bytecode instruction.

Compatibility

Supports CPython 3.12+, including 3.14's new opcodes and specialized instructions.

License

MIT

History

This project was created almost entirely by a coding agent, with little human checking. Use at own risk.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

friendly_dis-0.1.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

friendly_dis-0.1.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file friendly_dis-0.1.0.tar.gz.

File metadata

  • Download URL: friendly_dis-0.1.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.6

File hashes

Hashes for friendly_dis-0.1.0.tar.gz
Algorithm Hash digest
SHA256 68eb792a9aab7f4f33400333122292ba5490035b841ac0bff162a42ad30c9e3f
MD5 2c7770ac14854fdf93684e909da8385f
BLAKE2b-256 4b58cac26e2199aec96a064ae387dae7a98036e843f3c5732cacd5b250205efa

See more details on using hashes here.

File details

Details for the file friendly_dis-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for friendly_dis-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6e2087ac21f915e33549636e6a4919416db9bb2f762672c2cb0c602dff119f54
MD5 3544807c85eb4d5d88cddbae27ddfe39
BLAKE2b-256 5dfa835f465bbe1b613470a3d97faba122f7943de5ed45f49a8213f9b5f7caa3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page