Skip to content

MatthieuDartiailh/bytecode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

c8e7a4f · Jan 21, 2025
Nov 18, 2024
Jan 21, 2025
Aug 11, 2023
Jan 18, 2025
Jan 14, 2025
Feb 5, 2024
Jul 18, 2022
Nov 20, 2023
Dec 28, 2021
Feb 10, 2022
Feb 29, 2016
Feb 7, 2024
Jul 17, 2023
Jan 19, 2021
Aug 7, 2024
Oct 27, 2024

Repository files navigation

bytecode

Latest release on the Python Cheeseshop (PyPI) Continuous integration Documentation building Code coverage of bytecode on codecov.io Ruff

bytecode is a Python module to generate and modify bytecode.

Install bytecode: python3 -m pip install bytecode. It requires Python 3.8 or newer. The latest release that supports Python 3.7 and 3.6 is 0.13.0. The latest release that supports Python 3.5 is 0.12.0. For Python 2.7 support, have a look at dead-bytecode instead.

Example executing print('Hello World!'):

from bytecode import Instr, Bytecode

bytecode = Bytecode([Instr("LOAD_GLOBAL", (True, 'print')),
                     Instr("LOAD_CONST", 'Hello World!'),
                     Instr("CALL", 1),
                     Instr("POP_TOP"),
                     Instr("LOAD_CONST", None),
                     Instr("RETURN_VALUE")])
code = bytecode.to_code()
exec(code)