跳转到主要内容

Pyodide的导入钩子

项目描述

pyodide-importer

Pyodide + 外部文件导入支持

安装

Pyodide内部

import micropip
await micropip.install("pyodide-importer")

基本用法

from pyodide_importer import register_hook
register_hook("<Base URL where python scripts are in>")
import external_module

示例

import micropip
await micropip.install("pyodide-importer")
from pyodide_importer import register_hook
register_hook("https://raw.githubusercontent.com/ryanking13/pyodide-importer/main/test_modules/")

# https://raw.githubusercontent.com/ryanking13/pyodide-importer/main/test_modules/file_module.py
import file_module
file_module.hello()

# https://raw.githubusercontent.com/ryanking13/pyodide-importer/main/test_modules/regular_module/__init__.py
import regular_module
regular_module.hello()

高级用法

白名单模块导入

白名单模块将防止在查找不存在模块时生成冗余的HTTP请求。

register_hook(
    "<Base URL where python scripts are in>",
    modules=["module1", "module2"]
)

更改模块下载的路径

download_path 选项更改了模块将在虚拟文件系统中下载的路径,默认设置为当前工作目录。

register_hook(
    "<Base URL where python scripts are in>",
    download_path="/path/to/be/downloaded",
)

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于 安装软件包 的信息。

源分发

pyodide-importer-0.0.2.tar.gz (5.5 kB 查看散列)

上传时间:

构建分发

pyodide_importer-0.0.2-py2.py3-none-any.whl (6.7 kB 查看散列)

上传于 Python 2 Python 3

由以下机构支持