Registry / devops / pyrasite

pyrasite

JSON →
library2.0pypypi✓ verified 82d ago

Inject code into a running Python process. Attach a Python shell or run arbitrary code inside an already-running Python interpreter. Current version 2.0. Release cadence is low, last updated 2019.

pip install pyrasite
INSTALL
IMPORT
SIG · PYRASITE
P
pyrasite
devopspythonv2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PyrasiteIPC
from pyrasite import PyrasiteIPC
from pyrasite.tunnel import PyrasiteTunnel
inject
from pyrasite import inject
ReverseConnection
from pyrasite import ReverseConnection

Injects a simple print statement into the process with given PID. Requires gdb and ptrace permissions.

import os import pyrasite pid = os.environ.get('TARGET_PID', '1234') try: pyrasite.inject(pid, 'print("Hello from injected code")') except Exception as e: print(f'Failed: {e}')
pyrasite --version
Debug
Known issues
gotchaRequires gdb installed on the system and ptrace enabled (e.g., via yama ptrace_scope).
fix
Install gdb (apt-get install gdb) and run: echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
affects: all
gotchapyrasite injects code using GDB, which may not be available on minimal Docker containers or Alpine Linux.
fix
Use a full base image (e.g., ubuntu), or consider alternative methods like ptrace-based injectors.
affects: all
breakingVersion 2.0 changed the internal API; pyrasite.inject() is now the main entry point, replacing older pyrasite.main or `pyrasite` CLI calls from code.
fix
Use pyrasite.inject(pid, code) instead of subprocess calls to pyrasite CLI.
affects: 2.0
deprecatedThe CLI tool 'pyrasite' itself is still supported but considered legacy; programmatic use via pyrasite.inject() is preferred.
fix
Use the Python API: pyrasite.inject(pid, code)
affects: 2.0
gotchaPython 2 processes require a different payload tag? Not officially supported in 2.0.
fix
Only inject into Python 3 processes; Python 2 target processes may crash.
affects: 2.0
Upgrade
Version history
2.0latest on PyPI · released May 9, 2012
Audit
Dependencies
gdboptionalRequired at runtime to attach to processes; must be installed on the system (e.g., apt-get install gdb).
Agent activity
12 hits · last 30 days
node
12
Resources
pyrasite — pip install pyrasite · libregistry