Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

A library for inserting a piece of code into another piece of code

Project description


A library allows to insert one piece of code into another piece of code secretly, without changing line numbers.

The current version supports only Python 3.6. Also it allows to insert only functions without arguments.


A library has a useful function insert_code, which inserts which takes the original code, the code to insert and line number for insertion. The simplest example of usage from the examples directory:

from bytesinsert import insert_code

def hello():

def new_code():

code_orig = hello.__code__
code_to_insert = new_code.__code__
success, result = insert_code(code_orig, code_to_insert, 6)
if success:

The resulting output will be:


The insert_code function inserted code from the function new_code into the function hello by updating its bytecode.


This library can be easily installed with pip:

pip install bytesinsert

Project details

Download files

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

Files for bytesinsert, version 0.2.2
Filename, size File type Python version Upload date Hashes
Filename, size bytesinsert-0.2.2.tar.gz (6.9 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page