mcpField
P
polyglot-integration

polyglot-integration

github.com/aj-geddes开发373421 次安装34 周前更新
代码仓库

关于 polyglot-integration

polyglot-integration 是面向跨语言集成开发的技能,提供原生扩展、语言绑定和 gRPC 通信的参考指南与实践建议。

主要功能

  1. 01Node.js 原生扩展指南
  2. 02从 Node.js 集成 Python
  3. 03通过 PyO3 集成 Rust
  4. 04通过 Py4J 集成 Java
  5. 05gRPC 跨语言通信

适用场景

  1. 01从其他语言调用 Python ML 模型
  2. 02集成高性能 C、C++ 或 Rust 代码
  3. 03连接遗留系统
  4. 04实现多语言微服务通信

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill polyglot-integration

安装后在 Claude Code 中输入/polyglot-integration确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

references/
grpc-polyglot-communication.md
java-from-python-py4j.md
nodejs-native-addons-c.md
python-from-nodejs.md
rust-from-python-pyo3.md
scripts/
validate-pipeline.sh
templates/
pipeline.yaml

详细介绍

多语言集成

目录

概述

集成使用不同编程语言编写的代码,以发挥各自的独特优势并利用其生态系统。

适用场景

  • 使用 C/C++/Rust 编写对性能要求较高的代码
  • 从其他语言调用 Python 中的机器学习模型
  • 集成旧版系统
  • 利用特定语言的库
  • 构建多语言微服务架构

快速入门

最小可运行示例:

// addon.cc
#include <node.h>

namespace demo {

using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::String;
using v8::Value;
using v8::Number;

void Add(const FunctionCallbackInfo<Value>& args) {
  Isolate* isolate = args.GetIsolate();

  if (args.Length() < 2) {
    isolate->ThrowException(v8::Exception::TypeError(
        String::NewFromUtf8(isolate, "Wrong number of arguments")));
    return;
  }

  if (!args[0]->IsNumber() || !args[1]->IsNumber()) {
    isolate->ThrowException(v8::Exception::TypeError(
        String::NewFromUtf8(isolate, "Arguments must be numbers")));
// ... (see reference guides for full implementation)

参考指南

references/ 目录中的详细实现:

指南内容
Node.js 原生扩展(C++)Node.js 原生扩展(C++)
从 Node.js 调用 Python从 Node.js 调用 Python
从 Python 调用 Rust(PyO3)从 Python 调用 Rust(PyO3)
gRPC 多语言通信gRPC 多语言通信
从 Python 调用 Java(Py4J)从 Python 调用 Java(Py4J)

最佳实践

✅ 应该
  • 使用合适的进程间通信机制
  • 谨慎处理序列化
  • 实现恰当的错误处理
  • 考虑性能开销
  • 使用类型安全的接口
  • 记录集成点
❌ 不应该
  • 跨边界传递复杂对象
  • 忽略内存管理
  • 跳过错误处理
  • 在异步代码中使用阻塞调用

评论

支持 Markdown