Skip to main content

Python Universal Hex Library

A Python library to create and process micro:bit Universal Hex files.

Universal Hex is a superset of the Intel Hex format that can contain data for multiple micro:bit board versions (V1 and V2) in a single file.

Installation

To get easy access to the Universal Hex command line interface we recommend using uv:

uv tool install universal-hex

It can also be pip installed as a normal Python package and used as a library.

pip install universal-hex

Command Line Interface

A CLI is provided via the uhex entry point.

The separate command takes a Universal Hex file and created

# Separate a single Universal Hex into board-specific files
uhex separate file.hex

The join command takes multiple Intel Hex files to combine them into a Universal Hex:

# Join Intel Hex files for micro:bit V1 and V2 boards
uhex join --v1 one.hex --v2 two.hex

# Join using custom board IDs (repeat -b as needed)
uhex join -b 12345 board_a.hex -b 42 board_b.hex

# Mix V1/V2 with custom board IDs
uhex join --v1 one.hex -b 12345 other.hex --v2 two.hex
  • separate writes one output per board next to the input file using the pattern <input-stem>-board-<BOARD_ID>.hex (e.g. firmware-board-9900.hex).
  • join reads all provided hex files and writes the Universal Hex to stdout.
  • Validation happens during CLI parsing: files must exist, must not be directories, must end with .hex, and board IDs must be within 0–65535.

Library Usage

Creating a Universal Hex

from universal_hex import create_uhex, IndividualHex, BoardId

# Load your V1 and V2 hex files
v1_hex = open("program_v1.hex").read()
v2_hex = open("program_v2.hex").read()

# Create a Universal Hex
uhex = create_uhex([
    IndividualHex(hex=v1_hex, board_id=BoardId.V1),
    IndividualHex(hex=v2_hex, board_id=BoardId.V2),
])

# Save the result (always use \n line endings)
with open("program_universal.hex", "w", newline="\n") as f:
    f.write(uhex)

Separating a Universal Hex

from universal_hex import separate_uhex

# Load a Universal Hex file
uhex = open("program_universal.hex").read()

# Separate into individual Intel Hex files
ihexes = separate_uhex(uhex)

for ihex in ihexes:
    print(f"Board ID: 0x{ihex.board_id:04X}")
    # ihex.hex contains the Intel Hex content for this board

Checking if a file is a Universal Hex

from universal_hex import is_uhex

hex_content = open("some_file.hex").read()

if is_uhex(hex_content):
    print("This is a Universal Hex file")
else:
    print("This is a standard Intel Hex file")

Development

# Clone
git clone https://github.com/carlosperate/python-universal-hex.git
cd python-universal-hex

# Install with dev dependencies
uv sync

# Run all checkers and tests
uv run make.py check

License

MIT License - see LICENSE for details.

Related Projects

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

universal_hex-0.1.0.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

universal_hex-0.1.0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file universal_hex-0.1.0.tar.gz.

File metadata

  • Download URL: universal_hex-0.1.0.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for universal_hex-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5aa97154909885a882b3943cd766962a957190e4e2bcb64b0d6adea8dba5753e
MD5 cfa182760cf512c2507c89e1f18100b3
BLAKE2b-256 928e7c37edc036fea36f54e440e1a5bb20b890abf4e037e3a63547e2198a514d

See more details on using hashes here.

Provenance

The following attestation bundles were made for universal_hex-0.1.0.tar.gz:

Publisher: publish.yml on carlosperate/python-universal-hex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file universal_hex-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: universal_hex-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for universal_hex-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 377e4fa25efa1dd7094c05693aeded41c6f8e591799dab5b8eb393b87bd452b6
MD5 d934395164d31a93c61b74ec5befebe7
BLAKE2b-256 e1918cf0d11badac6c8d8c8ca73087d9faff8f617900acace834635f35424c05

See more details on using hashes here.

Provenance

The following attestation bundles were made for universal_hex-0.1.0-py3-none-any.whl:

Publisher: publish.yml on carlosperate/python-universal-hex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

0.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page