Skip to main content

Client for Debug Adapter Protocol

Project description

DAP Client: Debug Adapter Protocol Client for Python

DAP Client is a generic client-side implementation of the Debug Adapter Protocol (DAP) for Python. It provides a clean, strongly-typed API for interacting with debug adapters but is decoupled from the transport layer (IO), allowing integration into any framework (synchronous, asynchronous, GUI, etc.).

For a comprehensive example of how to build a debugger UI with this client, see sandbox.py implementation.

Key Features

  • Protocol-First: Implements the DAP state machine and message parsing without forcing a specific IO model.
  • Strongly Typed: Uses Pydantic models for request arguments and event bodies.
  • Easy Integration: Can be used with subprocess, socket, asyncio, or any other transport mechanism.

Installation

pip install dap-python

If you are developing/contributing to the code, use pip install -e . instead. I also support using poetry.

Quick Start

The DAPClient requires an IO handler to send and receive bytes from the debug adapter. The library acts as a translation layer:

  • You feed it raw bytes from the adapter -> It yields high-level Event objects.
  • You call methods like client.launch() -> It buffers raw bytes for you to send to the adapter.

Example: minimal synchronous runner

This example assumes you have an IO handler similar to sandbox/dap_io.py.

import time
from dap.client import DAPClient
from dap.events import InitializedEvent

# Import your IO handler (see sandbox/dap_io.py for a reference implementation)
from sandbox.dap_io import IO 

# 1. Start the debug adapter (e.g., debugpy)
adapter_cmd = "python -m debugpy.adapter"
io = IO(adapter_cmd)
io.start()

# 2. Initialize the DAP Client
client = DAPClient(
    clientID="my-debugger",
    clientName="My Custom Debugger",
    locale="en-US",
    pathFormat="path"
)

# 3. Send the Initialize Request
# client.send() returns the raw bytes that need to be sent to the adapter
io.write(client.send())

# 4. Event Loop
try:
    while True:
        # Read raw data from the adapter's stdout
        data = io.read()
        if data:
            # Feed data to the client to parse events
            events = client.recv(data)
            
            for event in events:
                print(f"Received: {event}")
                
                if isinstance(event, InitializedEvent):
                    print("Adapter Initialized!")
                    # Once initialized, we can configure and launch
                    client.launch(program="script.py", console="internalConsole")
                    client.configuration_done()
                    
                    # Flush requests generated by the above calls
                    io.write(client.send())

        time.sleep(0.01)
except KeyboardInterrupt:
    io.stop()

Architecture

The library is designed around the DAPClient class in dap.client.

Data Flow

[ Debug Adapter ] <== bytes ==> [ IO Handler ] <== bytes ==> [ DAPClient ] <== Objects ==> [ Your Application ]
  1. Send: You call client.step_in(threadId=1). The client updates its internal state and queues the JSON-RPC message. You call client.send() to get the bytes and write them to your transport.
  2. Receive: You read bytes from your transport and call client.recv(bytes). The client parses the buffer and yields Event, Response, or Request objects.

API Reference

DAPClient

The main entry point. Common methods include:

  • launch(...) / attach(...)
  • set_breakpoints(...) / configuration_done()
  • continue_execution(...) / step_in(...) / next(...)
  • stack_trace(...) / scopes(...) / variables(...)
  • disconnect()

See dap/client.py for the full list of supported methods and arguments.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dap_python-1.0.1.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dap_python-1.0.1-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file dap_python-1.0.1.tar.gz.

File metadata

  • Download URL: dap_python-1.0.1.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Windows/11

File hashes

Hashes for dap_python-1.0.1.tar.gz
Algorithm Hash digest
SHA256 fbe17ae816fd94d627ac4a1522d41b9a8d51f28886e097c016a8b2e435fae6b1
MD5 8273e0638de40eae721ab56c80b7e5a6
BLAKE2b-256 22dbacbf1316e9c579801e7d8da79243838761b534bd26401f1d6fc467922577

See more details on using hashes here.

File details

Details for the file dap_python-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: dap_python-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Windows/11

File hashes

Hashes for dap_python-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2888503a8e4b89c6224c2d1a8f8f1303bf749e11d53727f90e5ad4bceb92bece
MD5 c4b8c33630f0d2240a6761812fe71870
BLAKE2b-256 03842d5ebd54c12c4359f872c99d4a1222dcec2b328f0bc7a1e5390991db1214

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page