ProbableOdyssey

TIL: Boosting Your Python Debugging with `ipdb`

ipdb supercharges Python’s built-in pdb debugger by integrating it with IPython. It offers all pdb’s core features, plus:

Essentially, ipdb makes debugging more intuitive, efficient, and visually appealing, moving beyond pdb’s limitations. It’s a fantastic upgrade for any Python project!

ipdb can be installed like any other python package

pip install ipdb
# or with `uv`:
uv add ipdb

To use this in python, launch python with the env var PYTHONBREAKPOINT=ipdb.set_trace, so that when the command breakpoint() is encountered, it’ll launch ipdb instead of pdb

Using ipython, I’ve inserted this block into a startup script in ~/.ipython/profile_default/startup/start.py:

try:
    import ipdb
    import os
    os.environ["PYTHONBREAKPOINT"] = "ipdb.set_trace"
except ImportError:
    pass

So that when I’m using ipython in a project with ipdb, ipdb is automatically loaded!

To use the improved debugger in pytest --pdb, add this line to the [tool.pytest.ini_options] section of the pyproject.toml:

addopts = "--pdbcls=IPython.terminal.debugger:TerminalPdb"

Reply to this post by email ↪