惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LINUX DO - 最新话题
C
Cyber Attacks, Cyber Crime and Cyber Security
G
GRAHAM CLULEY
T
Tenable Blog
T
Threatpost
C
CXSECURITY Database RSS Feed - CXSecurity.com
I
Intezer
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
Security Latest
Security Latest
P
Privacy & Cybersecurity Law Blog
Google Online Security Blog
Google Online Security Blog
SecWiki News
SecWiki News
P
Palo Alto Networks Blog
TaoSecurity Blog
TaoSecurity Blog
Webroot Blog
Webroot Blog
Spread Privacy
Spread Privacy
O
OpenAI News
The Last Watchdog
The Last Watchdog
P
Proofpoint News Feed
C
Check Point Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
人人都是产品经理
人人都是产品经理
S
Security @ Cisco Blogs
Scott Helme
Scott Helme
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
月光博客
月光博客
S
Securelist
酷 壳 – CoolShell
酷 壳 – CoolShell
V
V2EX
T
Troy Hunt's Blog
W
WeLiveSecurity
GbyAI
GbyAI
N
News | PayPal Newsroom
Y
Y Combinator Blog
C
Cisco Blogs
H
Help Net Security
The GitHub Blog
The GitHub Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 【当耐特】
Jina AI
Jina AI
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
云风的 BLOG
云风的 BLOG
小众软件
小众软件
N
News and Events Feed by Topic

博客园 - 荣锋亮

just-git 纯js 的git 实现 阿里开源的UnifiedModel agno agentos interfaces 简单说明 agno agentos ag-ui 协议 agno agentos 暴露a2a 协议 agno gateway模式 agno 多agent 框架集成能力 agno agentos 简单说明 agno workflow 模式简单说明 agno team agent 简单说明 agno remote agent 简单说明 agno agent 使用 agno agent 平台 sshpiper 简单试用 sshpiper ssh 的反向代理服务 context-propagation spring reactor 的上下文传递包 nginx 发布1.31.2 了 reductstore 的一些部署模式 reductstore 数据写入模式 reductstore bridge 方便reductstore数据bridge 扩展 reductstore zenoh 集成 zenoh 1.9.x 一些新特性 ladybugdb嵌入式图数据库 BlockHound 检测 reactor阻塞调用的agent reductstore 高性能面向机器人以及IOT场景的存储以及流数据基石 zerofs 一些新功能 java nats request-many 支持的一些模式 java nats RequestMany context7 面向llm 以及ai代码编辑器的依赖包更新平台 NATS Agents Protocol nats 团队提出的agent 通信协议 metamcp mcp聚合&调度工具 llama-agents 的server 服务 mcp-proxy 桥接streamable http 以及stdio mcp 的工具 GhidraMCP Ghidra 的mcp服务 mcpcute 聚合mcp的工具 agent-tool-protocol 与mcp的集成 llama-agents 执行流程图查看 llama-agents 的异常处理 通过dbos 解决llama-agents workflow 持久执行问题 llama-agents workflow 持久化运行的一些玩法 llama-agents 状态管理 llama-agents stream events 处理 zerofs v1.1.1 aarch64 支持16k-64k page llama-agents step执行的一些模式 llmaindex workflows-py 变更为了llama-agents agent-tool-protocol 代码优先的agent tool 协议 ZeroFS 1.1.0 发布 chicory 原生jvm webassembly runtime quickjs4j 包含的几个模块 quickjs4j java 中安全运行js 的沙箱 supergateway 将stdio server 暴露为sse服务的ai gateway nats-server 2.14.0 发布 nuitka python 模块转so 模块 - 荣锋亮 llama-agents 的resource对象 turndown html 转markdown npm包 @langchain/node-vfs 简单试用 @langchain/node-vfs node vfs web-agent firecrawl 开源的web 数据agent CubeSandbox 腾讯开源的轻量级面向ai agent的的沙箱工具 new-api 统一ai gateway 平台 pyinstrument python 调用连profiler 工具 jsonhero Trigger 团队开可以友好查看json的工具 aiproxy 高性能ai gateway just-bash 面向agent 的bash restate 构建可靠应用的平台 java 一些raft 实现框架 opendataloader-pdf 开源pdf自动处理工具 sbproxy单一文件的ai gateway 以及反向代理服务 hyperframes agent 友好的通过html 的视频处理框架 open-semantic开放语义层 agentregistry 开源中心化可信可治理的ai registry py-spy 一些新特性 zerofs 1.0.9 包含了webui nanobot 基于mcp 构建agent的框架 gh-aw-firewall github agent workflow 防火墙 dbos-inc agent-skills dbos 的agent skills robustmq ai 领域的通信设施 dbos轻量级持久工作流框架 command-stream 试用 nats-top 类似top 监控nats的工具 nats-surveyor nats-server 监控工具 awesome-design-md 一些知名网站设计规范 zerofs 添加终端实时监控 command-stream支持实时流的命令行包 use-m 简单试用 use-m 动态下载以及加载js 模块 live-plugin-manager 试用 live-plugin-manager nodejs 插件框架 zx 支持的一些配置 zx 试用 zx 方便编写scripts 的工具 agent-infra sandbox 基于单容器的ai agent 沙箱环境 zerofs 支持prometheus metrics opencli 一个通过的转换任何web站点以及app 为cli的工具 wecom-cli 企业微信cli deepagentsjs langchain 开源的deep agent 框架 dingtalk-workspace-cli 悟空cli 结合nats 实现agent框架的融合集成 larksuite/cli agent 友好的飞书cli 工具 Scrapling 自适应的爬虫框架
python 动态加载模块
荣锋亮 · 2026-04-07 · via 博客园 - 荣锋亮

动态加载模块在插件化中很重要,但是在agent 周边也是比较重要的,比如我们基于ai 生成代码,同时需要动态加载执行代码模块,python 内置了不少方法以下简单说明下

通过importlib.import_module

注意此模式会加载到sys.modules 中,会有cache的问题,同时会有sys.path 查找的问题,可以通过importlib.reload 进行重新加载reload

  • 参考玩法
module = importlib.import_module(f"mymodules_{runner_id}.app")
importlib.reload(module)

通过importlib.util.spec_from_file_location

此模式就比较自由了,路径可以自己指定,每次都是新的module,同时不会cache 到sys.modules中

  • 参考玩法
spec = importlib.util.spec_from_file_location(module_name, path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)

说明

以上是动态加载的方法,使用好了价值还是比较大的,但是注意动态加载是不进行隔离的,实现加载模块以及依赖(通过uv ),可以参考如下

  • importlib.util.spec_from_file_location 模式
def load_module_from_path(module_name, path):
    try:
        spec = importlib.util.spec_from_file_location(module_name, path)
        module = importlib.util.module_from_spec(spec)
        # install dependencies if requirements.txt exists
        requirements_path = os.path.join(os.path.dirname(path), "requirements.txt")
        if os.path.exists(requirements_path):
            import subprocess
            subprocess.check_call(["uv", "pip", "install", "-r", requirements_path])
        spec.loader.exec_module(module)
        return module
    except ModuleNotFoundError as e:
        print(f"Error loading module {module_name} from path {path}: {e}")
       
  • importlib.import_module
def get_module_dir(module_name):
    spec = importlib.util.find_spec(module_name)
    if spec is None:
        raise ModuleNotFoundError(module_name)

    # package
    if spec.submodule_search_locations:
        return list(spec.submodule_search_locations)[0]

    # 普通模块
    return os.path.dirname(spec.origin)

def load_module_from_module_with_cache(module_name, *args, **kwargs):
    try:
        requirements_path = os.path.join(get_module_dir(f"plugins.{module_name}"), "requirements.txt")
        if os.path.exists(requirements_path):
            import subprocess
            subprocess.check_call(["uv", "pip", "install", "-r", requirements_path])
        return importlib.import_module(f"plugins.{module_name}.app")
    except ModuleNotFoundError:
        print(f"Module plugins.{module_name} not found, loading from path")
        raise ModuleNotFoundError(f"Module plugins.{module_name} not found, loading from path")

参考资料

https://docs.python.org/3/library/importlib.html

https://docs.python.org/3/library/importlib.html#module-importlib.util