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.
Install the package
Section titled “Install the package”uv add openocd-pythonpip install openocd-pythonpipx install openocd-pythonThe package installs both the Python library (import openocd) and a CLI tool (openocd-python).
Dependencies
Section titled “Dependencies”| Package | Version | Purpose |
|---|---|---|
cmsis-svd | >= 0.4 | SVD 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.
Install OpenOCD
Section titled “Install OpenOCD”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.
sudo pacman -S openocdsudo apt install openocdbrew install openocdDownload the latest release from openocd.org and add the bin directory to your system PATH.
git clone https://github.com/openocd-org/openocd.gitcd openocd./bootstrap./configuremakesudo make installVerify OpenOCD is installed and accessible:
openocd --versionVerify the installation
Section titled “Verify the installation”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:
openocd -f interface/cmsis-dap.cfg -f target/stm32f1x.cfgThen, 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:
openocd-python infoThis prints the target name, state, transport, adapter, and clock speed.
Development installation
Section titled “Development installation”To work on openocd-python itself, clone the repository and install the development dependencies:
git clone https://git.supported.systems/ryan/openocd-python.gitcd openocd-pythonuv sync --extra devThe dev extras include:
| Package | Purpose |
|---|---|
pytest >= 8.0 | Test runner |
pytest-asyncio >= 0.24 | Async test support |
ruff >= 0.8 | Linter and formatter |
Run the test suite (no hardware needed — all tests use a mock OpenOCD server):
uv run pytestRun the linter:
uv run ruff check src/ tests/Next steps
Section titled “Next steps”- First Connection — connect to OpenOCD and run your first command
- Quick Start — complete working examples for common tasks
- CLI Reference — use the
openocd-pythoncommand-line tool