Python
Debugger: debugpy (Microsoft) Status: Stable Python version: 3.8+
Prerequisites
bash
pip install debugpyVerify: python -m debugpy --version
Quick Start
bash
# Debug a script
krometrail launch "python app.py" --break app.py:42
# Debug a pytest test
krometrail launch "python -m pytest tests/test_order.py::test_gold_discount -x" \
--break order.py:147
# Debug Django
krometrail launch "python manage.py runserver" --break views.py:83
# Debug Flask
krometrail launch "flask run" --break routes.py:55Framework Auto-detection
pytest, Django, and Flask are auto-detected from the launch command. The adapter configures debugpy appropriately for each:
- pytest — disables test runner capture so breakpoints work correctly
- Django — enables Django template debugging, disables autoreload
- Flask — sets
WERKZEUG_RUN_MAIN=trueto prevent fork on autoreload
Conditional Breakpoints
Python expressions work directly in conditions:
bash
krometrail break "order.py:147 when discount < 0"
krometrail break "loop.py:25 when i == 99"
krometrail break "api.py:30 when request.method == 'POST'"Exception Breakpoints
bash
krometrail break --exceptions uncaught # only unhandled exceptions
krometrail break --exceptions raised # all raised exceptionsFor specific exception types, use a conditional breakpoint with isinstance.
Tips
- The Python adapter uses
python -m debugpy --listen :PORT --wait-for-clientunder the hood. You do not need to modify your code. debug_evaluateaccepts any valid Python expression including method calls, comprehensions, and f-strings.- Virtual environments are respected — the adapter uses the
pythonfound in your PATH or the one specified in the command. - Use
--stop-on-entryto pause on the first executable line (useful for understanding program structure).
Troubleshooting
Breakpoints not hit:
- Confirm the file path is correct relative to
cwd - Check that
krometrail doctorshows debugpy installed - If using a virtual environment, ensure it's activated before launching
debugpy import error in your program:
- debugpy is only used by Krometrail's adapter subprocess, not imported into your code directly