Did you know that you can add aliases to PDB with a ~/.pdbrc file?

I made one over the weekend with some very helpful aliases.

https://treyhunner.com/2026/04/customizing-pdb-with-pdbrc/

I can now use these to inspect an object (note that "dir" and "vars" are like the dir() & vars() functions but better):

attrs x
dir x
vars x

And I can find the source for a function with this:

src func

And print non-dunder locals nicely like this:

loc

#Python #debugging #PDB

Using a ~/.pdbrc file to customize the Python Debugger

Did you know that you can customize the Python debugger (PDB) by creating custom aliases within a .pdbrc file in your home directory or Pythonโ€™ โ€ฆ

This post was inspired by this poll:

https://mastodon.social/@treyhunner/116347015393379267

I was surprised that no one who answered knew about .pdbrc files before this weekend, including me.

I should have guessed that @nedbat would have a many-year-old blog post on this topic: https://nedbatchelder.com/blog/200704/my_pdbrc

Slightly more validation that I should dig through Ned's archive of posts more often.

My .pdbrc

When I need a Python debugger, I use the standard pdb debugger. Iโ€™m very low-tech about it: I set breakpoints by adding this line to my source: