{"id":13802640,"url":"https://github.com/peterhinch/micropython_data_to_py","last_synced_at":"2025-04-30T15:31:28.321Z","repository":{"id":59704397,"uuid":"83793505","full_name":"peterhinch/micropython_data_to_py","owner":"peterhinch","description":"A Python3 utility to convert an arbitrary binary file to Python source for storage in Flash","archived":false,"fork":false,"pushed_at":"2023-08-01T09:04:45.000Z","size":4,"stargazers_count":26,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-22T13:31:31.510Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/peterhinch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-03-03T11:55:22.000Z","updated_at":"2024-03-18T07:47:23.000Z","dependencies_parsed_at":"2024-01-07T21:53:50.846Z","dependency_job_id":"9f573843-fb9a-4482-99d7-4691dcf89ab5","html_url":"https://github.com/peterhinch/micropython_data_to_py","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhinch%2Fmicropython_data_to_py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhinch%2Fmicropython_data_to_py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhinch%2Fmicropython_data_to_py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhinch%2Fmicropython_data_to_py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peterhinch","download_url":"https://codeload.github.com/peterhinch/micropython_data_to_py/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224215505,"owners_count":17274798,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T00:01:49.202Z","updated_at":"2024-11-12T04:21:11.576Z","avatar_url":"https://github.com/peterhinch.png","language":"Python","readme":"# data_to_py.py\n\nA means of storing read-only data in Flash, conserving RAM.\n\nThe utility runs on a PC and converts an arbitrary binary file into a Python\nsource file. The generated Python file may be frozen as bytecode. Read-only\ndata may thus be stored in Flash and accessed with little RAM use.\n\nPlease see also [freezeFS](https://github.com/bixb922/freezeFS) - a utility by\n@bixb922 which allows a complete directory tree to be frozen and mounted as a\nfilesystem.\n\n## Arguments\n\nThe utility requires two arguments, the first being the path to a file for\nreading and the second being the path to a file for writing. The latter must\nhave a ``.py`` extension. If the output file exists it will be overwritten.\n\n## The Python output file\n\nThis instantiates a ``bytes`` object containing the data, which may be accessed\nvia the file's ``data()`` function: this returns a ``memoryview`` of the data.\n\nThe use of a ``memoryview`` ensures that slices of the data may be extracted\nwithout using RAM:\n\n```python\nimport mydata  # file mydata.py (typically frozen)\nd = mydata.data()  # d contains a memoryview\ns = d[1000:3000]  # s contains 1000 bytes but consumes no RAM\n```\n\nA practical example is rendering a JPEG file to an LCD160CR display. The Python\nfile ``img.py`` is generated using\n\n```\n$ ./data_to_py.py my_image.jpg img.py\n```\n\nThe file ``img.py`` may then be frozen, although for test purposes it can just\nbe copied to the target. The following code displays the image:\n\n```python\nimport lcd160cr\nimport img\nlcd = lcd160cr.LCD160CR('Y')\nlcd.set_orient(lcd160cr.PORTRAIT)\nlcd.set_pen(lcd.rgb(0, 0, 0), lcd.rgb(0, 0, 0))\nlcd.erase()\nlcd.set_pos(0, 0)\njpeg_data = img.data()\nlcd.jpeg(jpeg_data)  # Access the data and display it\n```\n\n## Validation\n\nThe utility can accept any file type as input, so no validation is performed.\nIf required, this must be done by the application at runtime. For example in\nthe above code, to be suitable for the device jpeg_data[:2] should be\n``0xff, 0xd8`` and jpeg_data[-2:] should be ``0xff, 0xd9``.\n","funding_links":[],"categories":["Libraries"],"sub_categories":["Storage"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterhinch%2Fmicropython_data_to_py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeterhinch%2Fmicropython_data_to_py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterhinch%2Fmicropython_data_to_py/lists"}