Registry / testing / pylink-square

pylink-square

JSON →
library2.0.1pypypi✓ verified 25d ago

PyLink is a Python package that provides an interface to SEGGER J-Link debug probes, allowing control and interaction with embedded targets from Python. It was developed by Square to integrate J-Link functionality into Python-based test infrastructure. The library is actively maintained, with the current version being 2.0.1, and typically sees updates for new features and bug fixes.

pip install pylink-square
INSTALL
IMPORT
SIG · PYLINK-SQUARE
P
pylink-square
testingpythonv2.0.1
Install
1.8s avg
Import
137ms
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.140s · 19.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.8s · import 0.134s · 20MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

JLink
from pylink import JLink
pylink
import pylink

This quickstart demonstrates how to establish a connection to a SEGGER J-Link debug probe and then connect to a target device. It then performs a basic operation, such as reading the target's IDCODE. Ensure `JLINK_SERIAL_NO` and `JLINK_TARGET_DEVICE` environment variables are set with your specific J-Link serial number and target CPU name, or replace the placeholder values. The SEGGER J-Link Software and Development Pack must be installed on your system.

import pylink import os # Replace with your J-Link's actual serial number (as a string). # Consider setting JLINK_SERIAL_NO and JLINK_TARGET_DEVICE as environment variables. jlink_serial_no = os.environ.get('JLINK_SERIAL_NO', 'YOUR_JLINK_SERIAL_HERE') target_device = os.environ.get('JLINK_TARGET_DEVICE', 'CORTEX-M4') # Example: 'ATSAM4S2B' or 'STM32F407VG' try: # Initialize JLink object jlink = pylink.JLink() # Open a connection to your J-Link probe jlink.open(serial_no=int(jlink_serial_no)) print(f"Connected to J-Link: {jlink.product_name} (Serial: {jlink_serial_no})") # Connect to the target device jlink.connect(target_device, verbose=True) print(f"Connected to target device: {target_device}") # Perform a simple operation, e.g., read target IDCODE if jlink.connected() and jlink.target_connected(): print(f"Target IDCODE: {hex(jlink.idcode())}") # Example: Reset the target # jlink.reset() else: print("Failed to establish full connection to target device.") except pylink.JLinkException as e: print(f"J-Link operation failed: {e}") except ValueError: print("Invalid J-Link serial number provided. Must be an integer.") finally: # Always close the J-Link connection if 'jlink' in locals() and jlink.opened(): jlink.close() print("J-Link connection closed.")
Debug
Known issues
breakingPython 2 support has been entirely dropped starting from PyLink version 2.0.0. Projects still using Python 2 will need to upgrade their Python environment or use an older version of PyLink.
fix
Migrate your project to Python 3.x. If unable, pin `pylink-square<2.0.0`.
affects: >= 2.0.0
gotchaPyLink requires the SEGGER J-Link Software and Development Pack to be installed on the system, as it wraps the native C SDK. The library will not function without the underlying J-Link shared library (DLL on Windows, .dylib on macOS, .so on Linux) being present and discoverable by PyLink.
fix
Download and install the appropriate J-Link Software and Development Pack from SEGGER's website for your operating system. Ensure the J-Link library path is correctly configured (e.g., via `PATH`, `LD_LIBRARY_PATH`, `DYLD_LIBRARY_PATH` environment variables, or by copying to a system library directory).
affects: All versions
gotchaMany operations, such as `open()`, `connect()`, `flash()`, and `erase()`, can raise 'Unspecified Error' exceptions. Common causes include: J-Link not physically connected, J-Link being used by another application, incorrect target device name, incorrect interface (JTAG vs. SWD), target not powered/connected, or the device not being properly halted before an operation.
fix
Refer to the `pylink` troubleshooting guide. Verify physical connections, ensure J-Link is not in use elsewhere, confirm target device name, interface, and power. For flash/erase, ensure the CPU is halted; sometimes a specific `set_reset_strategy` is needed for Cortex-M devices.
affects: All versions
gotchaFile paths passed to PyLink APIs (e.g., for flashing firmware) are now encoded using `os.fsencode()` to properly support UTF-8 file paths. If your application was implicitly relying on different encoding behavior for file paths prior to v2.0.0, this change might affect how non-ASCII paths are handled.
fix
Ensure that file paths are handled as expected by `os.fsencode()`. In most standard Python 3 applications, this change should be transparent or beneficial for UTF-8 paths.
affects: >= 2.0.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pylink'
The 'pylink' module is not installed or not found in the Python environment.
fix
Install the module using pip: 'pip install pylink-square'.
pylink.errors.JLinkException: Unspecified error.
A generic error occurred, possibly due to the J-Link device not being connected or being used by another application.
fix
Ensure the J-Link device is properly connected and not in use by other applications. Refer to the troubleshooting guide for more details.
pylink.errors.JLinkException: Could not find supported CPU
The target device's CPU is not recognized or supported by the J-Link.
fix
Verify that the correct target device is specified and that it is supported by the J-Link. Consult the device's documentation for compatibility information.
ImportError: No module named 'pylink'
The 'pylink' module is not installed or the import statement is incorrect.
fix
Install the module using pip: 'pip install pylink-square'. Ensure the import statement is correct: 'import pylink'.
AttributeError: module 'pylink' has no attribute 'JLink'
The 'pylink' module is not properly installed or the 'JLink' class is not accessible.
fix
Reinstall the module using pip: 'pip install --force-reinstall pylink-square'. Ensure the import statement is correct: 'from pylink import JLink'.
Upgrade
Version history
2.0.1latest on PyPI · released Mar 4, 2026
Audit
Dependencies
SEGGER J-Link Software and Development PackrequiredPyLink is a wrapper around the J-Link C SDK. The SEGGER J-Link drivers and shared libraries (DLL/SO) must be installed separately on the system for PyLink to function.
psutilrequiredUsed for system-level utilities, listed as an install requirement.
Agent activity
14 hits · last 30 days
node
10
OpenAI (training)
1
Resources
pylink-square — pip install pylink-square · libregistry