pyodide-importer API

pyodide_importer.register_hook(base_url: Union[str, List[str]], download_path: str = '', modules: Optional[List[str]] = None, update_syspath: bool = True)

Register import hook to sys.meta_path.

Parameters
  • base_url (str or List[str]) – URL(s) where the directory containing Python packages is served through HTTP/S

  • download_path (str) – the path in virtual file system where Python packages will be downloaded, default is current working directory

  • modules (List[str]) – a list, with the names of the root modules/packages that can be imported from the given URL

  • update_syspath (bool) – whether to add download_path to sys.path

Notes on module parameter: If this parameter is not specified, import statement will try to search a module everytime when the module is not found in local filesystem. This means every FAILED import statement will result in multiple 404 HTTP errors. So when you have fixed modules, using modules parameter to whitelist downloadable modules in recommended.

pyodide_importer.unregister_hook()

Unregister import hook from sys.meta_path.

After calling this method, new external modules cannot be downloaded and imported, while previously imported modules can be keep available.

pyodide_importer.add_module(module: Union[str, List[str]])

Add new module(s) that can be imported from URL.

Parameters

module (str or List[str]) – modules/packages that can be imported from the URL

pyodide_importer.available_modules()

Get the list of modules that can be imported from the URL.