API debugging guidelines¶
Note
This is an opinionated guide that only applies to VS Code users. If you use a different editor or IDE, these instructions will not apply to you.
This is the guide to debugging the API using VS Code. This uses Microsoft’s
debugpy package.
Prerequisites¶
Install the Python Debugger extension.
Set up a VS Code workspace for the Openverse monorepo.
Steps¶
Add a launch configuration to the Openverse workspace configuration. This configuration does the following things.
Specifies that the debugger used should be
debugpy.Configures the debugger to “attach” to a running process instead of launching a new one.
Specifies the port on which the
debugpyserver is running so that VS Code can connect to it.Maps source code in the local repo clone to paths inside the Docker container so you can set breakpoints in the editor.
{ // existing configuration "launch": { "version": "0.2.0", "configurations": [ { "name": "API", "type": "debugpy", "request": "attach", "connect": { "host": "localhost", "port": 50256 }, "pathMappings": [ { "localRoot": "${workspaceFolder:api}", "remoteRoot": "/api" } ], "justMyCode": true } ] } }
Edit the
compose.ymlfile inside theapi/directory to uncomment thecommandfield and port mapping for port 5678.Run the API server inside Docker using the instructions in the quickstart guide.
Connect the debugger to the running instance from the Run and Debug panel.

Read the Visual Code debugger’s official instructions to better understand how to use the debugger interface to accomplish tasks like setting breakpoints, watching variables etc.