Download `pyodide-lock.json` with results of micropip.freeze()
Opened this issue · 2 comments
micropip.freeze()
returns the pyodide-lock.json
contents, and it would be nice if there was some convenience function that would trigger the download of such pyodide-lock.json
.
Maybe something like,
def download_pyodide_lock():
from js import document, Blob, URL
blob = Blob.new([micropip.freeze()], {"type": "application/json;charset=utf-8"})
a = document.createElement("a")
a.href = URL.createObjectURL(blob)
a.download = "pyodide-lock.json"
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
Though it wouldn't work in a web-worker (and JupyterLite)
It would be nice if it could detect:
- In node use nodefs to write to disk
- In chrome use nativefs to do a save prompt
- Otherwise try download
This would be convenient for other things too, maybe adding a small package to Pyodide for this would be nice.
maybe adding a small package to Pyodide for this would be nice.
Making a separate package sounds good to me. People sometimes ask about how they can download files inside the virtual file system, and it would be nice if we can provide some way to do it in Python.
Though it might be reinventing the wheel as there exists a FileSaver.js, but FileSaver.js itself is a small, single file package, so probably we can just reference and rewrite FileSaver.js to work in Pyodide.