lovuikeng
lovuikeng•2mo ago

wasm export local file read

exporting notebook to wasm
$ uv tool run marimo@0.10.2 export html-wasm apps.py -o wasm --mode run
serve it on python http server, after loading the index file, caught
This cell raised an exception: FileNotFoundError('[Errno 44] No such file or directory: 'data.csv''
does wasm export support reading local file?
Solution:
It does not at the moment. We have an issue internally tracking this
Jump to solution
12 Replies
Hall
Hall•2mo ago
Someone will reply to you shortly. In the meantime, this might help:
Solution
Myles Scolnick
Myles Scolnick•2mo ago
It does not at the moment. We have an issue internally tracking this
Myles Scolnick
Myles Scolnick•2mo ago
Is difficult since we would need to bundle this And there is a limit of what wasm can support in terms of file size
lovuikeng
lovuikengOP•2mo ago
ok, just to confirm, thank you, wasm standalone looks really great feature to explore 🙂
mcaggio
mcaggio•2mo ago
not sure if I understood the question correctly, but if you want to make a file available to the pyodide kernel, provided the file is available for download from a url, you can download it to the local wasm kernel filesystem
from pyodide.http import pyfetch

response = await pyfetch("https://raw.githubusercontent.com/caggionim/marimo_rheofit/refs/heads/main/models.py")
with open('models.py', 'wb') as file:
file.write(await response.bytes())
from pyodide.http import pyfetch

response = await pyfetch("https://raw.githubusercontent.com/caggionim/marimo_rheofit/refs/heads/main/models.py")
with open('models.py', 'wb') as file:
file.write(await response.bytes())
mcaggio
mcaggio•2mo ago
I have an example in this repository https://github.com/caggionim/marimo_rheofit
GitHub
GitHub - caggionim/marimo_rheofit: testing_marimo_app
testing_marimo_app. Contribute to caggionim/marimo_rheofit development by creating an account on GitHub.
lovuikeng
lovuikengOP•2mo ago
thanks, true that reading CSV from URL does work, the intention here is to read from local file path
flipside
flipside•7d ago
Hi, I was wondering, how do you make a cell async? I want to use pyfetch both during dev and deployment but it complains "'await' outside async function" and I think this is because in your code, cell using pyfetch starts with async def, but not sure how I can configure that? https://github.com/caggionim/marimo_rheofit/blob/6b3b830c463ee724bf99710f1a56ef35676cfb52/rheology_flowcurvefit.py#L15
GitHub
marimo_rheofit/rheology_flowcurvefit.py at 6b3b830c463ee724bf99710f...
testing_marimo_app. Contribute to caggionim/marimo_rheofit development by creating an account on GitHub.
RJ Budzyński
RJ Budzyński•7d ago
Depending on where you want to download from, you may be struggling with CORS though.
mcaggio
mcaggio•7d ago
my understanding is that the pyfetch from pyodide.html returns a promise, not the actual response, so you need to await the response. When you use await in a marimo cell my understanding is that marimo automatically makes that cell async. In the example the second cell where await is used is defined as async
@app.cell
def __():
import sys
import marimo as mo
return mo, sys


@app.cell
async def __():
from pyodide.http import pyfetch

response = await pyfetch("https://raw.githubusercontent.com/caggionim/marimo_rheofit/refs/heads/main/models.py")
with open('models.py', 'wb') as file:
file.write(await response.bytes())

response = await pyfetch("https://raw.githubusercontent.com/caggionim/marimo_rheofit/refs/heads/main/rheo_widgets.py")
with open('rheo_widgets.py', 'wb') as file:
file.write(await response.bytes())
@app.cell
def __():
import sys
import marimo as mo
return mo, sys


@app.cell
async def __():
from pyodide.http import pyfetch

response = await pyfetch("https://raw.githubusercontent.com/caggionim/marimo_rheofit/refs/heads/main/models.py")
with open('models.py', 'wb') as file:
file.write(await response.bytes())

response = await pyfetch("https://raw.githubusercontent.com/caggionim/marimo_rheofit/refs/heads/main/rheo_widgets.py")
with open('rheo_widgets.py', 'wb') as file:
file.write(await response.bytes())
You are right but at least looks like it works when you host an app on Github pages you can download files from the same repository without problems.
RJ Budzyński
RJ Budzyński•7d ago
Yes, githubusercontent.com url work ok
lovuikeng
lovuikengOP•6d ago
reminder: marimo now makes serving file/data on WASM so much easier https://docs.marimo.io/guides/wasm/#including-data
WebAssembly notebooks - marimo
The next generation of Python notebooks

Did you find this page helpful?