pdbr: Pdb with Rich Library
pdbr is a Python debugging tool that enhances the standard `pdb` (Python Debugger) by integrating the `Rich` library, providing colorful and well-formatted terminal output. It is currently at version 0.9.7 and sees active development with frequent releases addressing compatibility and adding features. It aims to make the debugging experience more visually appealing and user-friendly by leveraging Rich's capabilities for tracebacks, variable inspection, and more.
Warnings
- gotcha When using Python's built-in `breakpoint()` function, ensure `pdbr` is imported beforehand, or set the `PYTHONBREAKPOINT` environment variable to `pdbr.set_trace` for `pdbr` to be activated. Otherwise, it will default to the standard `pdb`.
- breaking Compatibility with IPython 9.x series was specifically addressed in `pdbr` version 0.9.2. Older `pdbr` versions may exhibit unexpected behavior or errors when used with IPython 9.x due to changes in IPython's internal architecture, especially regarding color and theme handling.
- gotcha Configuration file locations and parsing for `pdbr` (e.g., for history or context settings) were adjusted in version 0.8.9 to better adhere to `XDG_CONFIG_HOME`. If you have custom configurations, they might need to be relocated or updated.
- gotcha Like its base `pdb`, `pdbr` does not inherently handle multithreaded applications gracefully. Breakpoints in one thread may interrupt all threads. For more isolated debugging in multithreaded contexts, consider using `pdb.Pdb()` to create an isolated debugger instance and then call `set_trace()` on that specific object.
Install
-
pip install pdbr -
pip install pdbr[ipython]
Imports
- set_trace
import pdbr; pdbr.set_trace()
Quickstart
import pdbr
def divide(a, b):
try:
result = a / b
except ZeroDivisionError:
print("Error: Division by zero detected, entering debugger...")
pdbr.set_trace() # Program execution will pause here
result = 0
return result
if __name__ == "__main__":
print(f"10 / 2 = {divide(10, 2)}")
print(f"5 / 0 = {divide(5, 0)}") # This call will trigger the debugger