Skip to main content
Help the Python Software Foundation raise $60,000 USD by December 31st!  Building the PSF Q4 Fundraiser

Inject code into a running Python process

Project description

Pyrasite lets you to inject arbitrary code into an unaltered running Python process.



Download the latest stable release from PyPi:

pip install pyrasite

You can also run the latest pyrasite from source:

git clone git://
cd pyrasite
python -m pyrasite.main

You can also fork pyrasite on GitHub:


The gui has been moved into it’s own repository:


from pyrasite.inject import CodeInjector

ci = CodeInjector(


Reverse Python Shell

This lets you easily introspect or alter any objects in your running process.

$ python
>>> x = 'foo'
$ pyrasite <PID> pyrasite/payloads/
$ nc -l 9001
Python 2.7.1 (r271:86832, Apr 12 2011, 16:15:16)
[GCC 4.6.0 20110331 (Red Hat 4.6.0-2)]
Type 'quit' to exit.
>>> print x
>>> globals()['x'] = 'bar'

Viewing the largest objects in your process

This payload uses meliae to dump all of the objects in your process to an objects.json file (currently dumped in the working directory of your process).

We recommend using python-meliae from your OS distribution, if available. If it is not, you will need to first install Cython, and then meliae seperately. If pip/easy_install does not work, you may need to use the tarball from the upstream website.

$ pyrasite <PID> pyrasite/payloads/

Pyrasite also provides a tool to view the values of largest objects in your process. This requires urwid to be installed.

$ pyrasite-memory-viewer <PID> objects.json

Reverse Shell

$ pyrasite <PID> pyrasite/payloads/
$ nc -l 9001
Linux tomservo #1 SMP Tue Aug 16 04:10:59 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
Type 'quit' to exit.
% ls

Call Graph

Pyrasite comes with a payload that generates an image of your processes call graph using pycallgraph.

$ pyrasite <PID> pyrasite/payloads/
$ pyrasite <PID> pyrasite/payloads/

The callgraph is then generated using graphviz and saved to callgraph.png. You can see an example callgraph here.

Dumping modules, thread stacks, and forcing garbage collection


Additional installation notes

Mac OS X

If you don’t want to override Apple’s default gdb, install the latest version of gdb with a prefix (e.g. gnu)

$ ./configure --program-prefix=gnu
$ pyrasite <PID> pyrasite/payloads/ --prefix="gnu"


Since version 10.10, Ubuntu ships with a controversial patch that restricts the scope of ptrace, which can be disabled by running:

echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope

Arch Linux

You can install pyrasite from the Arch User Repository If you want python debugging symbols, you may have to self compile python2.


#pyrasite on Freenode.


Luke Macken <>

David Malcolm <>

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 pyrasite, version 2.0beta5
Filename, size File type Python version Upload date Hashes
Filename, size pyrasite-2.0beta5.tar.gz (31.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page