GoesSoftware.SuperSDK.Python
5.0.2
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
The owner has unlisted this package.
This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package GoesSoftware.SuperSDK.Python --version 5.0.2
NuGet\Install-Package GoesSoftware.SuperSDK.Python -Version 5.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GoesSoftware.SuperSDK.Python" Version="5.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GoesSoftware.SuperSDK.Python" Version="5.0.2" />
<PackageReference Include="GoesSoftware.SuperSDK.Python" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add GoesSoftware.SuperSDK.Python --version 5.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: GoesSoftware.SuperSDK.Python, 5.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package GoesSoftware.SuperSDK.Python@5.0.2
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=GoesSoftware.SuperSDK.Python&version=5.0.2
#tool nuget:?package=GoesSoftware.SuperSDK.Python&version=5.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SuperSDK.Python
SuperSDK Python 进程桥接库,适用于 .NET 9 / Avalonia 桌面应用。
无需额外 Python 包(仅标准库),new GzPythonWrapper() 自动完成进程启动与连接。
安装
dotnet add package SuncodeSoftware.SuperSDK.Python
快速上手
1. 初始化(自动完成)
using SuperSDK.Python;
var py = new GzPythonWrapper();
// 构造函数自动以 python3 启动桥接进程,首次 CallAsync 前完成连接
2. 调用 Python 方法
// CallAsync(方法名, new { P1 = 参数1, P2 = 参数2, Timeout = 超时(默认5000ms) })
var result = await py.CallAsync("process", new { P1 = "input" });
if (result.Success)
// Python 已接受请求并在后台处理,结果通过 OnProgress 事件回传
Console.WriteLine($"请求已提交,ID: {result.RequestId}");
else
Console.WriteLine(result.Error); // 连接失败 / 方法未注册等
// C# 一行包装
public Task<GzResult> ProcessAsync(string input)
=> _py.CallAsync("process", new { P1 = input });
GzResult 字段:
| 字段 | 类型 | 说明 |
|---|---|---|
Success |
bool |
Python 是否已成功接受请求 |
RequestId |
string |
本次请求的唯一码,可与后续 progress 事件关联 |
Error |
string? |
失败时的错误信息(连接未就绪、方法未注册等) |
3. 接收 Python 推送的事件
Python 通过 publish() 推送两类消息:
- 系统消息(
GzEventType.System):如心跳,每 10 秒自动推送 - 回复消息(
GzEventType.Reply):携带RequestId,关联到某次CallAsync
推荐:继承重写虚方法(心跳和 progress 已在构造函数中内部订阅)
public class MyPythonBridge : GzPythonWrapper
{
protected override void OnProgress(GzEventMessage msg)
{
// msg.RequestId 对应发起请求时的 GzResult.RequestId
Console.WriteLine($"请求 {msg.RequestId} 进度: {msg.Data}");
}
protected override void OnHeartbeat(GzEventMessage msg)
{
Console.WriteLine($"心跳 {msg.Data}");
}
}
或者:直接订阅其他自定义事件
py.Subscribe("my_event", msg =>
Console.WriteLine($"收到事件: {msg.Data}"));
GzEventMessage 字段:
| 字段 | 类型 | 说明 |
|---|---|---|
Id |
string |
事件自身的唯一码 |
Type |
GzEventType |
System / Reply |
Event |
string |
事件名 |
RequestId |
string? |
关联的请求 ID(Reply 类型) |
Data |
string |
事件数据(字符串) |
4. 释放
await py.ReleaseAsync(); // 断开连接,终止 Python 进程
添加自定义方法(最小改动)
Python 侧(在 gz_methods.py 中添加一个函数):
@rpc_method
def process(params):
req_id = params.get("__request_id") # 请求唯一码(自动注入)
publish(data="处理中 50%", request_id=req_id) # 推送 progress 事件
publish(data="处理完成", request_id=req_id)
# 返回值被忽略,所有结果通过 publish 推送
C# 侧(一行包装 + 重写回调):
// 发起请求
public Task<GzResult> ProcessAsync(string input)
=> _py.CallAsync("process", new { P1 = input });
// 接收进度(继承方式,见上方第 3 节)
protected override void OnProgress(GzEventMessage msg)
=> Console.WriteLine($"[{msg.RequestId}] {msg.Data}");
API 参考
| 方法 | 说明 |
|---|---|
new GzPythonWrapper() |
自动启动 python3 进程 |
CallAsync(method, args) |
调用 Python RPC 方法,返回 GzResult |
Subscribe(eventName, handler) |
订阅 Python 推送的事件 |
Unsubscribe(eventName) |
取消某事件的全部订阅 |
ReleaseAsync() |
断开连接,终止进程 |
IsRunning |
Python 进程是否正在运行 |
要求
- .NET 9+
- Python 3.8+(推荐 3.14,仅使用标准库,无需 pip 安装任何包)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- SuncodeSoftware.SuperSDK.Core (>= 5.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 7.9.0 | 28 | 4/7/2026 |
| 7.8.0 | 77 | 4/4/2026 |
| 7.7.0 | 78 | 4/4/2026 |
| 7.6.0 | 76 | 4/4/2026 |
| 7.5.0 | 77 | 4/4/2026 |
| 7.4.0 | 80 | 4/4/2026 |
| 7.3.0 | 77 | 4/4/2026 |
| 7.2.0 | 79 | 4/3/2026 |
| 7.1.0 | 76 | 4/3/2026 |
| 7.0.0 | 74 | 4/1/2026 |
| 6.6.2 | 78 | 3/31/2026 |
| 6.6.0 | 78 | 3/31/2026 |
| 6.5.2 | 78 | 3/31/2026 |
| 6.5.0 | 79 | 3/31/2026 |
| 6.4.0 | 80 | 3/30/2026 |
| 6.3.0 | 84 | 3/30/2026 |
| 6.2.0 | 81 | 3/30/2026 |
| 6.1.1 | 97 | 3/28/2026 |
| 6.1.0 | 177 | 3/28/2026 |
Loading failed
talk data deverse 2