MCPcopy Create free account
hub / github.com/microsoft/debugpy

github.com/microsoft/debugpy @v1.8.21

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.8.21 ↗ · + Follow
9,534 symbols 33,085 edges 657 files ⚖ MIT 2,696 documented · 28% 31 cross-repo links updated 13d agov1.8.21 · 2026-06-01★ 2,463208 open issues

Browse by type

Functions 8,218 Types & classes 1,240 Endpoints 76
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

debugpy - a debugger for Python

An implementation of the Debug Adapter Protocol for Python 3.

Build Status GitHub PyPI PyPI

Coverage

OS Coverage
Windows Azure DevOps coverage
Linux Azure DevOps coverage
Mac Azure DevOps coverage

debugpy CLI Usage

For full details, see the Command Line Reference.

Debugging a script file

To run a script file with debugging enabled, but without waiting for the client to attach (i.e. code starts executing immediately):

-m debugpy --listen localhost:5678 myfile.py

To wait until the client attaches before running your code, use the --wait-for-client switch.

-m debugpy --listen localhost:5678 --wait-for-client myfile.py

The hostname passed to --listen specifies the interface on which the debug adapter will be listening for connections from DAP clients. It can be omitted, with only the port number specified:

-m debugpy --listen 5678 ...

in which case the default interface is 127.0.0.1.

To be able to attach from another machine, make sure that the adapter is listening on a public interface - using 0.0.0.0 will make it listen on all available interfaces:

-m debugpy --listen 0.0.0.0:5678 myfile.py

This should only be done on secure networks, since anyone who can connect to the specified port can then execute arbitrary code within the debugged process.

To pass arguments to the script, just specify them after the filename. This works the same as with Python itself - everything up to the filename is processed by debugpy, but everything after that becomes sys.argv of the running process.

Debugging a module

To run a module, use the -m switch instead of filename:

-m debugpy --listen localhost:5678 -m mymodule

Same as with scripts, command line arguments can be passed to the module by specifying them after the module name. All other debugpy switches work identically in this mode; in particular, --wait-for-client can be used to block execution until the client attaches.

Attaching to a running process by ID

The following command injects the debugger into a process with a given PID that is running Python code. Once the command returns, a debugpy server is running within the process, as if that process was launched via -m debugpy itself.

-m debugpy --listen localhost:5678 --pid 12345

Ignoring subprocesses

The following command will ignore subprocesses started by the debugged process.

-m debugpy --listen localhost:5678 --pid 12345 --configure-subProcess False

debugpy Import usage

For full details, see the API reference.

Enabling debugging

At the beginning of your script, import debugpy, and call debugpy.listen() to start the debug adapter, passing a (host, port) tuple as the first argument.

import debugpy
debugpy.listen(("localhost", 5678))
...

As with the --listen command line switch, hostname can be omitted, and defaults to "127.0.0.1":

debugpy.listen(5678)
...

Waiting for the client to attach

Use the debugpy.wait_for_client() function to block program execution until the client is attached.

import debugpy
debugpy.listen(5678)
debugpy.wait_for_client()  # blocks execution until client is attached
...

breakpoint() function

Where available, debugpy supports the standard breakpoint() function for programmatic breakpoints. Use debugpy.breakpoint() function to get the same behavior when breakpoint() handler installed by debugpy is overridden by another handler. If the debugger is attached when either of these functions is invoked, it will pause execution on the calling line, as if it had a breakpoint set. If there's no client attached, the functions do nothing, and the code continues to execute normally.

import debugpy
debugpy.listen(...)

while True:
    ...
    breakpoint()  # or debugpy.breakpoint()
    ...

Debugger logging

To enable debugger internal logging via CLI, the --log-to switch can be used:

-m debugpy --log-to path/to/logs ...

When using the API, the same can be done with debugpy.log_to():

debugpy.log_to('path/to/logs')
debugpy.listen(...)

In both cases, the environment variable DEBUGPY_LOG_DIR can also be set to the same effect.

When logging is enabled, debugpy will create several log files with names matching debugpy*.log in the specified directory, corresponding to different components of the debugger. When subprocess debugging is enabled, separate logs are created for every subprocess.

Core symbols most depended-on inside this repo

browse all functions →

Shape

Method 4,562
Function 3,656
Class 1,237
Route 76
Enum 3

Languages

Python94%
C5%
C++1%

Modules by API surface

src/debugpy/_vendored/pydevd/_pydevd_bundle/_debug_adapter/pydevd_schema.py824 symbols
src/debugpy/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_evaluator.c514 symbols
src/debugpy/_vendored/pydevd/tests_python/test_debugger_json.py280 symbols
src/debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/kernel32.py267 symbols
src/debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/breakpoint.py210 symbols
src/debugpy/_vendored/pydevd/tests_python/test_debugger.py185 symbols
src/debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/process.py182 symbols
src/debugpy/_vendored/pydevd/pydevd.py173 symbols
tests/timeline.py162 symbols
src/debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/advapi32.py143 symbols
src/debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/interactive.py130 symbols
src/debugpy/_vendored/pydevd/tests_python/debugger_unittest.py118 symbols

Datastores touched

CrashesDatabase · 1 repos

For agents

$ claude mcp add debugpy \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page