pyrasite

Inject code into running Python processes

What is pyrasite?

Inject code into running Python processes

Overview of pyrasite

What it is

pyrasite is a set of tools for injecting arbitrary code into running Python processes. It uses gdb (version 7.3 or later) to attach to a target process and execute Python code within that process's interpreter. The project is hosted on GitHub and is licensed under GPL-3.0.

Key features

  • Inject arbitrary Python code into a running CPython process without restarting it.
  • Supports injection across different Python versions (CPython 3.9 through 3.15).
  • Provides a memory viewer as an optional extra (install with pip install pyrasite[memory-viewer]).
  • Offers two injection methods: the default queued method (using Py_AddPendingCall) for multi-threaded programs, and a direct method (--inject-method direct) for processes blocked in C.
  • Works on Linux systems with appropriate ptrace configuration.

Use cases

Debugging live production issues by inspecting or modifying the state of a running Python process. Adding logging or diagnostics to a long-running server without restarting it. Patching a running application to fix a bug or change behavior on the fly. Extracting data from a process that cannot be stopped.

Getting started

Install pyrasite using pipx or pip:pipx install pyrasiteFor the optional memory viewer:pip install pyrasite[memory-viewer]Basic usage:pyrasite See the repository README for detailed instructions on ptrace configuration and injection methods.

License and pricing

pyrasite is open source under the GPL-3.0 license. No pricing information is provided; it is free to use.

Based on the project's public README and repository metadata.

Add this badge to your README

Featured on YunoDB Badge styles & help

Maintain this project? Show that it is featured on YunoDB.

Markdown[![Featured on YunoDB](https://yunodb.com/badge/lmackenpyrasite.svg)](https://yunodb.com/tools/lmackenpyrasite?utm_source=github&utm_medium=badge)
HTML<a href="https://yunodb.com/tools/lmackenpyrasite?utm_source=github&utm_medium=badge"><img src="https://yunodb.com/badge/lmackenpyrasite.svg" alt="Featured on YunoDB" height="20"></a>