GoesSoftware.SuperSDK.Python
5.2.3
dotnet add package GoesSoftware.SuperSDK.Python --version 5.2.3
NuGet\Install-Package GoesSoftware.SuperSDK.Python -Version 5.2.3
<PackageReference Include="GoesSoftware.SuperSDK.Python" Version="5.2.3" />
<PackageVersion Include="GoesSoftware.SuperSDK.Python" Version="5.2.3" />
<PackageReference Include="GoesSoftware.SuperSDK.Python" />
paket add GoesSoftware.SuperSDK.Python --version 5.2.3
#r "nuget: GoesSoftware.SuperSDK.Python, 5.2.3"
#:package GoesSoftware.SuperSDK.Python@5.2.3
#addin nuget:?package=GoesSoftware.SuperSDK.Python&version=5.2.3
#tool nuget:?package=GoesSoftware.SuperSDK.Python&version=5.2.3
SuperSDK.Python
SuperSDK Python 进程桥接库,适用于 .NET 9 / Avalonia 桌面应用。
无需额外 Python 包(仅标准库),new GzPythonWrapper() 自动完成进程启动与连接。
内置 GzPyConsoleCtrl Avalonia 控件,一行 AXAML 即可展示实时日志、状态、心跳 —— 不需要在 ViewModel 中声明任何额外字段。
安装
dotnet add package GoesSoftware.SuperSDK.Python
就这么简单
ViewModel — 只需暴露 Wrapper 本身
using ReactiveUI;
using SuperSDK.Python;
public class MainWindowViewModel : ReactiveObject
{
private MyWrapper? _py;
public MyWrapper? Py { get => _py; private set => this.RaiseAndSetIfChanged(ref _py, value); }
// 启动
private Task StartAsync()
{
if (Py != null) return Task.CompletedTask;
Py = new MyWrapper(); // 自动启动 Python 进程
return Task.CompletedTask;
}
// 释放
private async Task ReleaseAsync()
{
var py = Py; Py = null;
if (py != null) await Task.Run(() => py.Dispose());
}
}
AXAML — 直接绑定到 Wrapper 属性
<Window xmlns="https://github.com/avaloniaui"
xmlns:pyctrl="clr-namespace:SuperSDK.Python.Controls;assembly=SuperSDK.Python">
<TextBlock Text="{Binding Py.Status, FallbackValue=未启动}"/>
<TextBlock Text="{Binding Py.LastHeartbeat, FallbackValue=-}"/>
<pyctrl:GzPyConsoleCtrl WrapperId="{Binding Py.Id}" Height="200"/>
</Window>
就是这样。 ViewModel 不需要 PyStatus、PyHeartbeat、PyWrapperId 等任何中转属性。
GzPythonWrapper 实现了 INotifyPropertyChanged,Avalonia 绑定引擎直接感知其变化。
自定义 Wrapper(继承 GzPythonWrapper)
Python 侧(PythonScripts/demo.py):
from gz_sdk import gz_service, publish
@gz_service
class DemoService:
def process(self, params):
req_id = params.get("__request_id")
publish(data="处理中 50%", request_id=req_id)
publish(data="处理完成", request_id=req_id)
C# 侧(MyWrapper.cs):
using SuperSDK.Python;
public class MyWrapper : GzPythonWrapper
{
// csproj 中声明:<EmbeddedResource Include="PythonScripts\**\*.py" />
// 基类约定自动加载,无需 override ScriptSources
public Task<GzResult> ProcessAsync(string input)
=> CallAsync("process", new { P1 = input });
}
结果通过 GzPythonLogMsg(level = Progress)自动送达 GzPyConsoleCtrl,无需手动处理。
调用 Python 方法
var result = await py.CallAsync("process", new { P1 = "input" });
if (result.Success)
Console.WriteLine($"请求已提交,ID: {result.RequestId}");
else
Console.WriteLine(result.Error);
GzResult 字段:
| 字段 | 类型 | 说明 |
|---|---|---|
Success |
bool |
Python 是否已成功接受请求 |
RequestId |
string |
本次请求的唯一码 |
Error |
string? |
失败时的错误信息 |
GzPyConsoleCtrl 属性
| 属性 | 类型 | 默认 | 说明 |
|---|---|---|---|
WrapperId |
string |
"" |
绑定 GzPythonWrapper.Id,自动订阅该实例日志 |
MaxLines |
int |
300 |
最大保留行数 |
ShowTimestamp |
bool |
true |
是否显示时间戳 |
控件无主题属性,始终跟随全局主题,调用 SuperApp.ToggleTheme() 即可,无需配置。
API 参考
| 成员 | 类型 | 说明 |
|---|---|---|
Id |
string |
实例唯一 8 字符码,绑定到 GzPyConsoleCtrl.WrapperId |
Status |
string |
当前状态文本(自动维护:未启动 / 启动中 / 运行中 / 已释放) |
LastHeartbeat |
string |
最近一次心跳内容(自动更新) |
IsRunning |
bool |
Python 进程是否正在运行 |
CallAsync(method, args) |
Task<GzResult> |
调用 Python RPC 方法 |
ReleaseAsync() |
Task |
断开连接,终止进程 |
要求
- .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. |
-
net9.0
- GoesSoftware.SuperSDK.Core (>= 5.2.3)
- GoesSoftware.SuperSDK.UI (>= 5.2.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
ok to use