Skip to content

A Python3 utility to convert an arbitrary binary file to Python source for storage in Flash


Notifications You must be signed in to change notification settings


Folders and files

Last commit message
Last commit date

Latest commit



3 Commits

Repository files navigation

A means of storing read-only data in Flash, conserving RAM.

The utility runs on a PC and converts an arbitrary binary file into a Python source file. The generated Python file may be frozen as bytecode. Read-only data may thus be stored in Flash and accessed with little RAM use.

Please see also freezeFS - a utility by @bixb922 which allows a complete directory tree to be frozen and mounted as a filesystem.


The utility requires two arguments, the first being the path to a file for reading and the second being the path to a file for writing. The latter must have a .py extension. If the output file exists it will be overwritten.

The Python output file

This instantiates a bytes object containing the data, which may be accessed via the file's data() function: this returns a memoryview of the data.

The use of a memoryview ensures that slices of the data may be extracted without using RAM:

import mydata  # file (typically frozen)
d =  # d contains a memoryview
s = d[1000:3000]  # s contains 1000 bytes but consumes no RAM

A practical example is rendering a JPEG file to an LCD160CR display. The Python file is generated using

$ ./ my_image.jpg

The file may then be frozen, although for test purposes it can just be copied to the target. The following code displays the image:

import lcd160cr
import img
lcd = lcd160cr.LCD160CR('Y')
lcd.set_pen(lcd.rgb(0, 0, 0), lcd.rgb(0, 0, 0))
lcd.set_pos(0, 0)
jpeg_data =
lcd.jpeg(jpeg_data)  # Access the data and display it


The utility can accept any file type as input, so no validation is performed. If required, this must be done by the application at runtime. For example in the above code, to be suitable for the device jpeg_data[:2] should be 0xff, 0xd8 and jpeg_data[-2:] should be 0xff, 0xd9.


A Python3 utility to convert an arbitrary binary file to Python source for storage in Flash







No releases published