Hexadecimal Record File Handler

0.5.1 · active · verified Thu Apr 16

hexrec is a Python library designed to handle hexadecimal record files, such as Intel HEX and Motorola S-records. It provides tools for parsing, creating, and manipulating these records and converting between raw data blocks and record formats. The current version is 0.5.1, and it maintains an active release cadence with periodic updates to support newer Python versions and improve features.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a data Block, convert it into a list of Intel HEX records, and parse a single Intel HEX record line back into a `IntelHexRecord` object using `hexrec.blocks` and `hexrec.records`.

from hexrec.blocks import Block
from hexrec.records import IntelHexRecord

# Create a Block instance with an address and data
data = b'\x00\x01\x02\x03\x04\x05\x06\x07'
block = Block(address=0x1000, data=data)
print(f"Created Block: Address=0x{block.address:04X}, Data={block.data.hex()}")

# Convert the Block to IntelHexRecord instances
records = block.to_records(record_type=IntelHexRecord)

print("Generated Intel HEX Records:")
for record in records:
    print(record.to_line())

# Example of parsing an Intel HEX record line
line = ':10100000000102030405060708090A0B0C0D0E0F00'
parsed_record = IntelHexRecord.from_line(line)
print(f"\nParsed Record: Address=0x{parsed_record.address:04X}, Data={parsed_record.data.hex()}")

view raw JSON →