1

I need to use some files in my Pyscript algorithm, and I know Pyscript can´t access local files because of a security issue. But my question is, can I somehow upload those files to a virtual file system, because otherwise I'm going to be unable to run my script. When using the open() function, I'm getting an error where the file isn't found.

13
  • Do you mean "my Pyscript-based algorithm"? There's ways to provide files to work with pyscript. They are covered in the documentation and a good summary of the situation as of the middle of last year is here. Have you looked over that? "can I somehow upload those files to a virtual file system"? There's options related to that. You can upload the files to where your html files containing pyscript code are hosted and then the pyscript code can see the files like a web. Or you can use this ... Commented Feb 23, 2024 at 16:12
  • <continued> to fetch the file from a URL. This example gets the CSV file from github using the latest approaches it seems. I was using the older ways earlier this month and they worked, see specifically last paragraph here. The other answer there may help you as well as it is current and worked. My feelings are though that if you are trying to do data exploration with pyodide, ... Commented Feb 23, 2024 at 16:13
  • <continued> which is what pyscript uses to run the code, and need to be flexible with what files you access because they change, then you may as well use JupyterLite where there is a familiar user interface where you can simply drag-and-drop the files from your local system into the virtual file system running in your browser. If you make anything useful, like a Jupyter .ipynb file, then download it back to your local system's file system because if something goes kablooie with your browser or you clear the cache, ... Commented Feb 23, 2024 at 16:14
  • <continued> you lose the files developed within the virtual file system of JupyterLite at this time. In other words, always best to treat the virtual file system as if it is a remote system you don't own and may go away unexpectedly. Commented Feb 23, 2024 at 16:14
  • @Wayne Thank you very much for your answer. Im trying to access de MSINT database, and I have the files locally. I could try to get a github URL to fetch, but don't know which one to choose. Im not very experienced in this world, and I'm having trouble understanding some of the concepts. Would it help if I posted the code? I tried inputting your solution using the [[fetch]] function, but now I'm running into an error. Uncaught YAMLException$1 YAMLException$1 at throwError (//node_modules/js-yaml/dist/js-yaml.mjs:1277:3) Commented Feb 23, 2024 at 16:54

1 Answer 1

1

If you have the files available "to the network" (either on a web server, or served locally with something like python3 -m http.serve or another simple dev server), you can uses the [files] key in py-config to load those files into the virtual filesystem.

The older [[fetch]] key is also available, but it's a little error-prone due to its complexity and options, so [files] is currently the recommended way forward.

Sign up to request clarification or add additional context in comments.

4 Comments

Also, from another question you recently asked, it looks like you're still using the alpha release of pyscript, which has had many releases since then. See the examples at pyscript.github.io/docs/2024.2.1/beginning-pyscript .
@Wayne does it work if you link directly to the most recent release (https://pyscript.net/releases/2024.03.2/core.js as of today) instead of /latest?
Yes, it works with https://pyscript.net/releases/2024.3.2/core.js , which I suspect is what you meant since that other one is not valid. (Now working here.) Part of the issue is that leaving the plugins directive in py-config caused it to fail silently it seemed. I did notice though you mentioned plugins as an issue in your post about the November overhaul and thought maybe best to try without it. However, I don't see the interactive terminal working ...
<continued> as spelled out here which made figuring out how to get Element working again difficult. (I was hoping I could keep trying import statements in an interactive console.) I stumbled through at least importing pydom from pyweb, yet gettting it to toggle visibility of a div didn't seem to work and so I made the div not hidden to get past that small hitch.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.