Debugpy support in Anki

Is your feature request related to a problem? Please describe.
No, this is a new feature.

Describe the solution you’d like
It will be very beneficial to have debugpy available for debugging in Anki. Allowing for a debugpy.listen to attach a debugger will be most beneficial for addon development.

Benefits for a GUI based IDE debugger connecting via debugpy include:

  • debug breakpoints, so we can:
  • see how the code is running, seeing step-by step logic, e.g. in if-statements and try-except blocks
  • easily inspect and modify variables

As an addon developer (Ankimon), I found my coding workflow to be much more efficient when I set a debugpy integration.

Describe alternatives you’ve considered
Set-up integration via Python venv with aqt - This is what I use, and I have made a whole setup for this at Github: h0tp-ftw/anki-vscode. I have full access to debugger as I run it through VS Code. However, this leads to cross-platform issues, and hard to set up for someone new to Anki coding.

Anki’s current support for PDB - it is good, but the ease that debugpy gives in the IDE is very valuable. Especially for new developers, debugpy provides a very easy-to-use interface.

Injecting code for debugpy into Anki’s code through an addon - this may be a security violation and also not permitted, so I would like to suggest native integration.

Running debugpy through an addon - Anki instantly kills the attempt to debugpy.listen, here is a bit of the terminal output from my code. I also get the “Anki Already Running” error.

Initial setup…
Starting Anki 25.02.7…

2025-08-29 11:38:41,790:INFO:aqt.mediasrv: Serving on http://127.0.0.1:48214

[ANKI-DEBUGPY-ADDON] debugpy imported successfully

[ANKI-DEBUGPY-ADDON] Attempting to debugpy.listen on port 9001… 

0.00s - Debugger warning: The os.path.realpath.code.co_filename (ntpath)

0.00s - is not absolute, which may make the debugger miss breakpoints.

0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.

Anki starting…

Initial setup…

Starting Anki 25.02.7…

Thank you for your consideration, and I absolutely love Anki. If this suggestion is welcome, I can submit a PR for my proposed method to add this to code. Thank you developers <3

2 Likes

Breakpoints at least already work. I have this launch config:

ankiscripts.run is a script that basically executes aqt.run():

2 Likes

I have achieved the same thing via the integration I mentioned:

Although your script is more convenient for that, it’d still be nice to have native support because it can be hard to set up.

2 Likes