micropython-microbit-fs
A Python library and command line tool to inject and extract files from MicroPython Intel Hex file for the BBC micro:bit.
Features
- Inject files into a MicroPython hex file for flashing to micro:bit.
- Extract files from an existing micro:bit MicroPython hex file.
- Get device info from hex, including filesystem size and MicroPython version.
- Command-line interface for easy scripting and automation.
- Includes the latest MicroPython releases for micro:bit V1 and V2 boards.
Installation
To install this terminal tool we recommend using uv:
uv tool install micropython-microbit-fs
It can also be installed via pip as a normal Python package:
pip install micropython-microbit-fs
Command Line Interface
The package includes a microbit-fs command for working with hex files from
the terminal.
Usage
Display device information:
$ microbit-fs info micropython.hex
Device: micro:bit V2
MicroPython version: micro:bit v2.1.2+0697c6d on 2023-10-30; MicroPython v1.18 on 2023-10-30
Flash page size: 4096 bytes
Filesystem size: 20480 bytes
Filesystem start: 0x0006D000
Filesystem end: 0x00073000
List files in a hex file:
$ microbit-fs list micropython_with_files.hex
File Size
──────────────────────────────────────── ────────────
main.py 183 bytes
──────────────────────────────────────── ────────────
Total (1 files) 183 bytes
Add files to a hex file:
# Add a single file using an existing MicroPython hex
microbit-fs add main.py --hex-file micropython.hex
# Add multiple files with a custom output file
microbit-fs add main.py helper.py --hex-file micropython.hex --output output.hex
# Use bundled micro:bit V1 MicroPython hex (latest version)
microbit-fs add main.py --v1=latest
# Use bundled micro:bit V2 MicroPython hex (latest version)
microbit-fs add main.py --v2=latest --output my_program.hex
# Use a specific MicroPython version
microbit-fs add main.py --v1=1.1.1 --output output.hex
microbit-fs add main.py --v2=2.1.2 --output output.hex
List available bundled MicroPython versions:
$ microbit-fs versions
Bundled MicroPython hex files:
micro:bit V1:
- 1.1.1
micro:bit V2:
- 2.1.2
Extract files from a hex file:
# Extract all files to the current directory
microbit-fs get micropython_with_files.hex
# Extract all files to a specific directory
microbit-fs get micropython_with_files.hex --output-dir ./extracted
# Extract a specific file
microbit-fs get micropython_with_files.hex --filename main.py
# Overwrite existing files without prompting
microbit-fs get micropython_with_files.hex --force
Library Quick Start
Add files to a MicroPython hex
import micropython_microbit_fs as microbit_fs
# Read your MicroPython hex file
with open("micropython.hex") as f:
micropython_hex = f.read()
# Create files to add
files = [
microbit_fs.File.from_text("main.py", "from microbit import *\ndisplay.scroll('Hello!')"),
microbit_fs.File.from_text("helper.py", "def greet(name):\n return f'Hello {name}'"),
]
# Add files and get new hex string
new_hex = microbit_fs.add_files(micropython_hex, files)
with open("micropython_with_files.hex", "w") as f:
f.write(new_hex)
Get files from a MicroPython hex
import micropython_microbit_fs as microbit_fs
# Read hex file with embedded files
with open("micropython_with_files.hex") as f:
hex_data = f.read()
# Get all files
files = microbit_fs.get_files(hex_data)
for file in files:
print(f"{file.name}: {file.size} bytes")
print(file.get_text())
Get device information
import micropython_microbit_fs as microbit_fs
with open("micropython.hex") as f:
hex_data = f.read()
info = microbit_fs.get_device_info(hex_data)
print(f"Device: micro:bit {info.device_version.value}")
print(f"MicroPython: {info.micropython_version}")
print(f"Filesystem size: {info.fs_size} bytes")
print(f"Flash page size: {info.flash_page_size} bytes")
Use bundled MicroPython hex files
import micropython_microbit_fs as microbit_fs
# List available bundled versions (dict keyed by device)
versions = microbit_fs.list_bundled_versions()
# {1: ['1.1.1'], 2: ['2.1.2']}
v1_versions = versions[1]
v2_versions = versions[2]
# Get the latest bundled hex for micro:bit V1
hex_data = microbit_fs.get_bundled_hex(1)
# Get a specific version
hex_data = microbit_fs.get_bundled_hex(2, "2.1.2")
# Add files to the bundled hex
files = [microbit_fs.File.from_text("main.py", "from microbit import *")]
new_hex = microbit_fs.add_files(hex_data, files)
with open("my_program.hex", "w") as f:
f.write(new_hex)
Development
This project uses uv for project management.
Setup
git clone https://github.com/carlosperate/python-microbit-fs.git
cd python-microbit-fs
uv sync --all-extras --dev
Development Commands
This project includes a make.py script to automate common development tasks.
# Run all checks (lint, typecheck, format check, test with coverage)
uv run python make.py check
# Format code (ruff check --fix + ruff format)
uv run python make.py format
# Show all available commands
uv run python make.py help
License
MIT License - see LICENSE for details.
Related Projects
- This project has been ported (AI assisted) from the original microbit-fs TypeScript library.
- This project packs the files inside a micro:bit MicroPython hex, which can then be flashed to a micro:bit. Alternatively, to read and write files from a running micro:bit device over USB, the microFs CLI tool can be used.
Metadata
Release files for micropython-microbit-fs 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| micropython_microbit_fs-0.1.2.tar.gz | 784.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| micropython_microbit_fs-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.6 MB
Release files / micropython_microbit_fs-0.1.2.tar.gz
| Download URL | micropython_microbit_fs-0.1.2.tar.gz |
|---|---|
| Size | 784.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8a487567fdb551d6e38e03329946536aa1c2931d3c17ee396b265dc8da8f12ef
|
|
BLAKE2b-256 checksum How to use checksums |
b1aac5bbf2330b5664ef0064d5e06742391c51effd0b83769b626bf24a4b7d73
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 4, 2026.
Transparency logRelease files / micropython_microbit_fs-0.1.2-py3-none-any.whl
| Download URL | micropython_microbit_fs-0.1.2-py3-none-any.whl |
|---|---|
| Size | 788.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
38a4c3fad722278359581bc08744ae26837a17eb8b561c610b61cde52e5b982f
|
|
BLAKE2b-256 checksum How to use checksums |
6423878896310c96e3a719331c8dcf1c4baec511f2e3e09e2b55c90876ad4007
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 4, 2026.
Transparency log