DAP Client is an up-to-date generic client side implementation of the Debug Adapter Protocol (DAP) that is used in IDEs, editors and other tools to communicate with different debuggers. The client is not tied to any specific debugger, so it can be used to interact with any debug adapter that implements the DAP protocol, significantly reducing the effort required to build a new debugging tool. For a list of supported debug adapters, see the official specification.
- Sans I/O Implementation: A protocol-only client that can be integrated into any I/O framework.
- Abstract Clients: Ready-to-use threaded and asyncio clients for immediate integration.
- Flexible Architecture: Easily extensible to support various debugging scenarios.
Install DAP Client using pip:
pip install dap-python
The following example demonstrates how to use the async client to connect to a debugpy
debug adapter server that is running on port 1234.
python -m debugpy --listen localhost:1234 --wait-for-client hello.py
import asyncio
from dap import AsyncServer
async def main():
server = AsyncServer("debugpy", port=1234)
try:
await server.start()
except asyncio.CancelledError:
await server.stop()
if __name__ == "__main__":
asyncio.run(main())
The sans I/O client allows you to implement your own I/O mechanism:
from dap import Client
from dap.responses import Initialized
client = Client()
client.launch(no_debug=True)
# get the request data
request = client.send()
# send the request using your I/O implementation
# ...
# feed the response data to the client
for result in client.receive(response_data):
if isinstance(result, Initialized):
print("The debug adapter is initialized.")
...
The threaded client provides a simple interface for synchronous usage:
from dap import ThreadedServer
server = ThreadedServer("debugpy", port=1234)
server.start()
client = server.client
# Use the client synchronously
client.launch()
client.disconnect()
server.stop()
The asyncio client offers an asynchronous interface:
import asyncio
from dap import AsyncServer
async def debug_session():
server = AsyncServer("debugpy", port=1234)
server.start()
client = server.client
client.launch()
client.disconnect()
server.stop()
asyncio.run(debug_session())
DAP Client is released under the MIT License.