PuDB: a console-based visual debugger for Python
PuDB is a full-screen, console-based visual debugger for Python. It aims to provide the benefits of modern GUI-based debuggers in a lightweight, keyboard-friendly terminal interface. PuDB allows developers to debug code directly in their terminal environment, with features like syntax-highlighted source, stack, breakpoints, and variables all visible simultaneously. The current version is 2025.1.5, and it maintains an active development and release cadence.
Warnings
- breaking Python 2.7 support was officially dropped after PuDB version 2019.2. Users requiring Python 2.7 must use an older version of the library.
- gotcha Starting from `pudb v2022.1.2`, the debugger automatically breaks and jumps directly into the function that raises an unhandled exception. In older versions, it would report the exception at the call site without automatically jumping, allowing users to debug the exception handler directly.
- gotcha Redirecting the standard output of a Python script (e.g., `python script.py > log.txt`) can cause PuDB's TUI to display in a small, squished, and often unusable window. This is typically due to the underlying `urwid` library's inability to correctly detect terminal dimensions when output is redirected.
- gotcha Using the built-in `breakpoint()` function to invoke PuDB requires Python 3.7 or newer and the `PYTHONBREAKPOINT` environment variable set to `pudb.set_trace`. Without this, `breakpoint()` will default to `pdb`.
- gotcha When attempting to debug from a separate terminal using the `PUDB_TTY` environment variable, you must first get the `tty` path (e.g., `/dev/pts/3`) and ensure the target terminal isn't actively reading by running a placeholder command like `perl -MPOSIX -e pause`. Failing to do so can result in unexpected behavior or a non-responsive debugger.
- gotcha The `pudb.set_trace()` function installs a SIGINT handler (for Ctrl-C) to break into the debugger. This handler is specific to the main thread and may not function as expected in other threads of your application.
Install
-
pip install pudb
Imports
- set_trace
from pudb import set_trace; set_trace()
- breakpoint
export PYTHONBREAKPOINT="pudb.set_trace" # Then in your code: breakpoint()
- set_trace (remote)
from pudb.remote import set_trace; set_trace()
Quickstart
import pudb
def factorial(n):
if n == 0:
return 1
else:
pudb.set_trace() # Execution will pause here
return n * factorial(n-1)
print(f"Factorial of 5 is: {factorial(5)}")