Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to access Pyodide APIs to customize init #88

Open
billti opened this issue Nov 1, 2023 · 3 comments
Open

How to access Pyodide APIs to customize init #88

billti opened this issue Nov 1, 2023 · 3 comments
Labels
documentation Improvements or additions to documentation

Comments

@billti
Copy link

billti commented Nov 1, 2023

I've read through the docs, a bunch of issues, and played around with a few of the templates (the GitHub starter and "jupyter lite" commands), but can't figure out how to do this, so maybe an area for docs improvement.

How do you access the Pyodide APIs to configure the pyodide kernel before user environments (REPL, Notebooks) are made available in JupyterLite?

In this particular case, a package I want to use is only shipped as native binaries and doesn't have a pyodide compatible build available, but can be easily provided by a JavaScript shim and registered via pyodide.registerJsModule (see https://pyodide.org/en/stable/usage/faq.html#how-do-i-create-custom-python-packages-from-javascript ), so I want to run this before-hand in the kernel at startup. How should this be done?

@billti billti added the documentation Improvements or additions to documentation label Nov 1, 2023
@andeplane
Copy link
Contributor

andeplane commented Nov 2, 2023

@jtpio maybe it makes sense to add a set of pre and post scripts in jupyter-lite.json? Something like

{
  "jupyter-lite-schema-version": 0,
  "jupyter-config-data": {
    "litePluginSettings": {
      "@jupyterlite/pyodide-kernel-extension:kernel": {
        "pyodideUrl": "./path/to/custom/pyodide/pyodide.js",
        "packages": ["numpy", "pandas", "scipy", "matplotlib"], // Install these packages
        "preKernelLoadScript": "preKernelLoadScript.js", // Run this script before kernel is loaded, with pyodide available
        "postKernelLoadScript": "postKernelLoadScript.js" // Run this script after kernel is loaded
      }
    }
  }
}

where the preKernelLoadScript.js can be something like

const preKernelLoad = async (pyodide, otherRelevantStuff) => {
  // Do stuff with pyodide
}
export default preKernelLoad

I can have a look if this looks interesting.

@jtpio jtpio transferred this issue from jupyterlite/jupyterlite Feb 14, 2024
@jtpio
Copy link
Member

jtpio commented Feb 14, 2024

I can have a look if this looks interesting.

Thanks!

I guess this could indeed be experimented with. And made opt-in, so site administrators would have to explicitly choose to enable such feature.

@jtpio
Copy link
Member

jtpio commented Feb 14, 2024

I moved the issue to the https://github.com/jupyterlite/pyodide-kernel repo since this seems to be more specific to that kernel.

Alternatively, it may be possible to implement such behavior as a more generic JupyterLab extension, that would work with any kernel and also with JupyterLab (just an idea, haven't checked more into the details to see if it's feasible).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants