pdbwhereami: A Python Debugging Utility

Debugging is a core part of development. However, finding the root cause of an error is often time-consuming. The pdbwhereami module makes this process faster. It provides simple functions that give context such as file name, function name, and line number.
Purpose of pdbwhereami
The utility offers lightweight helpers for debugging Python code:
whoamiwhereamiwhocalledmecalledtreewhosdaddy
Each of these functions adds valuable runtime information, making debugging easier and logs more meaningful.
Where is it Useful?
The module helps developers in several areas of debugging and code maintenance.
1. Debugging
- Identifying Errors: When errors occur, knowing the exact file and line number reduces guesswork. Developers can quickly pinpoint the problem.
- Traceability: Logging file names and line numbers allows developers to follow the program flow across multiple files.
2. Logging
- Detailed Logs: Adding context makes log messages easier to read and interpret.
- Automated Monitoring: Monitoring systems can detect recurring problem areas automatically. As a result, issues can be fixed faster.
3. Assertions and Debug Builds
- Assertions: Using
assert()withwhoamiorwhereamihighlights logical errors clearly during development. - Conditional Compilation: Extra debugging data can be included in debug builds without affecting production releases.
4. Documentation and Maintenance
- Code Reviews: Contextual error messages help reviewers understand code behavior more effectively.
- Maintenance: Logs with file names and line numbers help new developers fix issues quickly.
👉 By combining these functions, developers can build code that is easier to debug, maintain, and scale.
How to Use pdbwhereami
from pdbwhereami import whoami, whereami, whocalledme, calledtree, whosdaddy
def debug_utility():
whereami()
whereami("I am in test_whereami")
whereami(obsolete_path=True)
whocalledme()
whocalledme(obsolete_path=True)
whocalledme(path_depth=6)
calledtree()
tstr = calledtree(verbose=False)
print(tstr)
print()
whosdaddy()
Example Output
[bhagavan/test.py:8]:debug_utility ->
[bhagavan/test.py:9]:debug_utility -> I am in test_whereami
[/home/bhagavan/test.py:10]:debug_utility ->
#2[/home/bhagavan/test.py:16]:debug_utility <--
#1[/home/bhagavan/test.py:25]:main <--
#0[/home/bhagavan/test.py:27]:
<module> <--
[main] ->
This output shows the file, line, and function context. Therefore, developers can quickly trace execution flow.
Installation
Using pip
pip install pdbwhereami
Using Source
git clone https://github.com/bhagavansprasad/pdbwhereami.git
cd pdbwhereami
pip install ./
Integration with Logging Frameworks
One of the strongest features of pdbwhereami is its ability to integrate with logging frameworks.
- Built-in Python logging: Add file and line context in log messages.
- Third-party loggers (e.g., loguru): Enhance logs with caller information automatically.
import logging
from pdbwhereami import whereami
logging.basicConfig(level=logging.DEBUG)
def process_data():
logging.debug(whereami("Processing started"))
Frequently Asked Questions (FAQ)
1. What is pdbwhereami? It’s a Python debugging utility that adds runtime context such as file name, line number, and function name.
2. How is it different from pdb?
pdbis an interactive debugger that pauses execution.pdbwhereamiis a tracing and logging tool that provides context without stopping the program.
pdb vs pdbwhereami
| Feature / Aspect | pdb (Python Debugger) | pdbwhereami (Debugging Utility) |
|---|---|---|
| Purpose | Interactive step-through debugging. | Runtime logging and tracing. |
| Execution Flow | Halts execution for inspection. | Runs without interruption. |
| Ease of Use | Requires commands (n, s, b). | Simple function calls. |
| Output | Interactive console. | Log-like contextual output. |
| Best For | Debugging complex logic. | Logging, tracing, and code reviews. |
| Integration | Not logging-friendly. | Works with Python logging tools. |
| Production | Not suitable. | Can be used safely in production. |
👉 Quick takeaway:
Use pdb for interactive debugging. Choose pdbwhereami when you want logging, traceability, and faster runtime context without halting execution.
Related Keywords
- Python debugging utility
- Debugging in Python
- Python logging tools
- Python developer productivity
- Trace function calls in Python
About the Author
Bhagavan Prasad Expert in Python Automation, Debugging Tools, and Developer Productivity Utilities.
Teacher | Founder | Author | AI ML Learner | Technical Director | Embedded Engineer | Automation Engineer | Engineering Manager | Product Owner | C Programmer | Network Security Expert | Kernel Developer
Source Code: GitHub – pdbwhereami