Welcome to equip’s documentation!
equip is a small library that helps with Python bytecode instrumentation. Its API is designed to be small and flexible to enable a wide range of possible instrumentations.
The instrumentation is designed around the injection of bytecode inside the bytecode of the program to be instrumented. However, the developer does not need to know anything about the Python bytecode.
The following example shows how to write a simple instrumentation tool that will print all method called in the program, along with its arguments:
import sys
import equip
from equip import Instrumentation, MethodVisitor, SimpleRewriter
BEFORE_CODE = """
print ">> START"
print "[CALL] {file_name}::{method_name}:{lineno}", {arguments}
print "<< END"
"""
class MethodInstr(MethodVisitor):
def __init__(self):
MethodVisitor.__init__(self)
def visit(self, meth_decl):
rewriter = SimpleRewriter(meth_decl)
rewriter.insert_before(BEFORE_CODE)
instr_visitor = MethodInstr()
instr = Instrumentation(sys.argv[1])
if not instr.prepare_program():
return
instr.apply(instr_visitor, rewrite=True)
This program requires the path to the program to instrument, and will compile the source to generate the bytecode to instrument. All bytecode will be loaded into its representation, and the MethodInstr visitor will be called on all method declarations.
When a change is required (i.e., the code actually needs to be instrumented), the Instrumentation will overwrite the pyc file.
Running the instrumented program afterwards does not require anything but executing it as you would usually do. If the injected code has external dependencies, you can simply modify the PYTHONPATH to point to the required modules.
Metadata
Release files for equip 0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| equip-0.1.tar.gz | 25.1 kB | Without provenance | Details for equip-0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| equip-0.1-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for equip-0.1-py2.py3-none-any.whl |
Total release size: 58.6 kB
Release files / equip-0.1.tar.gz
| Download URL | equip-0.1.tar.gz |
|---|---|
| Size | 25.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d667c25f9b4bb9d060eef799b6fed715565c1840c754c1f257292083bd1883ea
|
|
BLAKE2b-256 checksum How to use checksums |
c1d56b0ffdd5255e5479894bc0a79430216843ab0c6f3591a8a7a9909e829660
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / equip-0.1-py2.py3-none-any.whl
| Download URL | equip-0.1-py2.py3-none-any.whl |
|---|---|
| Size | 33.5 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
5588c763c7aceb034a90661432b88cca4a229d522ecb71fa790c58e3cefa5601
|
|
BLAKE2b-256 checksum How to use checksums |
6cf9cfbe8302096d75f4cbc56c2785c9a02b36c44e4639283fa2e7c98b0257b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for equip 0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.