Skip to content

Installation

openocd-python requires Python 3.11 or later and a working OpenOCD installation. The library itself has a single dependency: cmsis-svd for SVD register decoding.

Terminal window
uv add openocd-python

The package installs both the Python library (import openocd) and a CLI tool (openocd-python).

PackageVersionPurpose
cmsis-svd>= 0.4SVD file parsing for peripheral register decoding

No other Python dependencies are required. The library uses only the standard library for networking (asyncio), subprocess management, and data types.

openocd-python communicates with OpenOCD over its TCL RPC interface. You need OpenOCD installed and either already running or available on your PATH so the library can spawn it.

Terminal window
sudo pacman -S openocd

Verify OpenOCD is installed and accessible:

Terminal window
openocd --version

After installing both openocd-python and OpenOCD, run a quick check to confirm everything is working.

First, start OpenOCD with your target configuration. For example, with a CMSIS-DAP probe and an STM32F1 target:

Terminal window
openocd -f interface/cmsis-dap.cfg -f target/stm32f1x.cfg

Then, in another terminal, verify the Python package can connect:

from openocd import Session
with Session.connect_sync() as ocd:
state = ocd.target.state()
print(f"Target: {state.name}, State: {state.state}")

You can also verify using the CLI:

Terminal window
openocd-python info

This prints the target name, state, transport, adapter, and clock speed.

To work on openocd-python itself, clone the repository and install the development dependencies:

Terminal window
git clone https://git.supported.systems/ryan/openocd-python.git
cd openocd-python
uv sync --extra dev

The dev extras include:

PackagePurpose
pytest >= 8.0Test runner
pytest-asyncio >= 0.24Async test support
ruff >= 0.8Linter and formatter

Run the test suite (no hardware needed — all tests use a mock OpenOCD server):

Terminal window
uv run pytest

Run the linter:

Terminal window
uv run ruff check src/ tests/