Performing file accessing and modifying actions in jupyterlab extension

Hey guys, I am trying out the Jupyterlab extension ecosystem.
Right now I’m interested to do these following tasks:

  • list down the files in a directory
  • read the contents of the file listed
  • create a new file
  • write on that new file

After observing, I’ve noticed that these actions can already be performed in jupyter notebook, but I am having trouble doing the same in my jupyterlab app.

For the first task, I have read this issue from github: Accessing local files · Issue #9951 · jupyterlab/jupyterlab · GitHub about not being able to access jupyterlab files. If I understood the issue correctly, jupyterlab extension cannot perform the task.

For the 2nd task, I do know that we can get the content of the current file. However, can we read a different file(eg .py) from the current file directory?. So we have obtained the filename and path from the previous step, and now we would like to read the content of that file.

For the last 2 tasks,
I do know that my application is able to perform a “Save As…” action, which is technically a “create new file” and “write on that file”, but I am not sure whether it is the recommended way of doing it without going through some hacks.

So is there a way of doing all of this from a frontend Jupyterlab extension? Or would you recommend going with a server approach?

Thanks

1 Like

Any update on the above?

1 Like

An extension can use a number of JupyterLab extension points to work with files.

For example, an extension can:

  • use lightly coupled commands for a number of these file actions
  • get a token for the IDocumentManager and do more things directly
  • use the ServiceManager from app.services.contents and use the REST API directly
2 Likes