Registry / data / intelhex

intelhex

JSON →
library2.3.0pypypi✓ verified 23d ago

IntelHex is a Python library for manipulating Intel HEX files, which are commonly used for programming microcontrollers and memory devices. It provides functionalities to read, write, parse, modify, and analyze HEX file data. The current version is 2.3.0, with a release cadence that addresses bug fixes and introduces new API features as needed.

pip install intelhex
INSTALL
IMPORT
SIG · INTELHEX
I
intelhex
datapythonv2.3.0
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.3.0 · 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.000s · 18.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 19MB
16MB installed
● package 16MB
Code
Verified usage

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

IntelHex
from intelhex import IntelHex

This quickstart demonstrates how to load an Intel HEX file, read and modify data, and then write the changes back to a new HEX file. It uses a temporary directory for file operations and highlights the use of `eolstyle` during file writing, which is crucial for cross-platform compatibility.

import tempfile import os from intelhex import IntelHex # Create a dummy HEX file content hex_content = """ :10010000214601360121470136007E012321460119FF :100110002146017E17C20001FF50013001360120202F :00000001FF """.strip() # Use a temporary file for demonstration with tempfile.TemporaryDirectory() as tmpdir: hex_filepath = os.path.join(tmpdir, "example.hex") with open(hex_filepath, "w") as f: f.write(hex_content) print(f"Created dummy hex file at: {hex_filepath}") # Load the Intel HEX file ih = IntelHex() ih.loadhex(hex_filepath) print(f"Loaded hex file with {len(ih.segments())} segments.") # Read a byte at a specific address address_to_read = 0x100 byte_value = ih[address_to_read] print(f"Byte at {hex(address_to_read)}: {hex(byte_value)}") # Modify a byte ih[0x100] = 0xAA print(f"Modified byte at {hex(address_to_read)} to: {hex(ih[address_to_read])}") # Write the modified data to a new HEX file output_hex_filepath = os.path.join(tmpdir, "modified.hex") # Using eolstyle='LF' explicitly (see warnings) ih.write_hex_file(output_hex_filepath, byte_count=16, eolstyle='LF') print(f"Modified hex file written to: {output_hex_filepath}") # Basic verification with open(output_hex_filepath, "r") as f: modified_content = f.read() if ":10010000AA4601360121470136007E012321460127" in modified_content: print("Verification successful: Modified byte found in output.") else: print("Verification failed.")
intelhex --version
Debug
Known issues
gotchaIn IntelHex v2.3.0, the `IntelHex.segments()` method introduced a new optional parameter `min_gap` with a default value of `1`. This means segments with gaps smaller than 1 byte (i.e., touching segments) will now be consolidated into a single segment by default, which changes the behavior compared to previous versions that strictly separated all non-overlapping segments.
fix
If you require strict separation of all non-overlapping segments, explicitly set `min_gap=0` when calling `ih.segments(min_gap=0)`. Adjust `min_gap` as needed to control segment consolidation behavior.
affects: >=2.3.0
deprecatedVersions of IntelHex prior to 2.0 had significant Python 3 compatibility issues or required the `2to3` tool. While improvements were made in 2.0, ongoing fixes for Python 3 compatibility, especially for command-line scripts, continued through versions 2.1 and 2.2.
fix
For new projects or existing Python 3 projects, always use `intelhex` version 2.0 or newer. For Python 2 projects, using `intelhex` >= 2.0 also provides better cross-compatibility and bug fixes.
affects: <2.0
gotchaWhen writing Intel HEX files using `IntelHex.write_hex_file()` (available since v2.2) or `IntelHex.tofile()` with `format='hex'` (available since v2.3.0), the default `eolstyle` is 'native' (OS-dependent). This can lead to issues if the target device or programmer expects specific line endings (e.g., CRLF for Windows-style, LF for Unix-style) regardless of the host OS.
fix
Always explicitly set the `eolstyle` parameter to `'CRLF'` or `'LF'` when writing HEX files, e.g., `ih.write_hex_file(filepath, eolstyle='CRLF')`, to ensure consistent line endings compatible with your target environment.
affects: >=2.2
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'intelhex'
The 'intelhex' library is not installed in the Python environment being used, or the Python interpreter cannot find the installed package.
fix
Ensure the library is installed using pip for the correct Python interpreter: `pip install intelhex` or `pip3 install intelhex`.
intelhex.HexRecordError: Hex file contains invalid record
This error occurs when the Intel HEX file being parsed is malformed, containing incorrect record lengths, types, checksum mismatches, or other structural inconsistencies.
fix
Validate the HEX file's integrity and format. Use a HEX file viewer or editor to identify and correct the specific issue (e.g., incorrect checksum, invalid record type, truncated line). Often, the error message will point to a specific line or record type.
intelhex.NotEnoughDataError
This exception is raised when attempting to read data from an `IntelHex` object at an address range that extends beyond the available data within the loaded HEX file.
fix
Before accessing data, verify the address range and data length against the actual data present in the `IntelHex` object, or use methods that safely handle sparse data, such as checking `ih.get(address)` for `0xFF` (default fill byte) or iterating through `ih.segments()`.
intelhex.AddressOverlapError
This error indicates that the Intel HEX file being processed contains data records that overlap in their memory addresses, meaning different data is specified for the same memory location.
fix
Examine the source of the HEX file to identify and resolve the overlapping address ranges. This often requires correcting the linker script or memory allocation in the build process that generated the HEX file.
Upgrade
Version history
2.3.0latest on PyPI · released Oct 20, 2020
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
intelhex — pip install intelhex · libregistry