Provider-V2 平台插件 SDK — 第三方平台适配器开发与加载
Project description
provider-sdk
Provider-V2 通用插件 SDK。
平台适配器只是可选扩展(extensions.platform),不是 SDK 核心。
安装
pip install provider-sdk
快速开始
plugins/
my_plugin/
_manifest.json
plugin.py
from provider_sdk import ProviderPlugin, Route, Hook, API
class MyPlugin(ProviderPlugin):
async def on_load(self) -> None:
self.ctx.logger.info("loaded")
@Route("/plugins/my/status", methods=["GET"])
async def status(self) -> dict:
return {"ok": True}
def create_plugin() -> MyPlugin:
return MyPlugin()
核心概念
| 概念 | 说明 |
|---|---|
ProviderPlugin |
插件基类,生命周期 + 配置 |
create_plugin() |
模块级工厂函数 |
_manifest.json |
插件元数据与依赖 |
@Route / @Hook / @API |
向 Host 声明组件 |
self.ctx |
运行时上下文(日志 / 配置 / HTTP) |
插件类型
plugin_type |
说明 |
|---|---|
general(默认) |
通用插件,声明 Route/Hook/API |
platform |
额外提供 PlatformAdapter,供网关注册 |
示例
examples/hello_plugin/— 通用插件examples/echo_platform/— 平台扩展插件
Developer Guide
Provider 插件开发指南
定位
provider-sdk 是通用插件 SDK,约定包括:
- 独立包,禁止
import src.* plugin.py+create_plugin()+_manifest.jsonProviderPlugin生命周期 +PluginContext- 装饰器声明组件
平台适配器(PlatformAdapter)是可选扩展,放在 provider_sdk.extensions.platform,仅供 plugin_type=platform 的插件使用。
目录结构
plugins/<plugin-name>/
_manifest.json
plugin.py
config.toml # 可选,Host 管理
Manifest
{
"manifest_version": 1,
"id": "author.my-plugin",
"name": "My Plugin",
"version": "0.1.0",
"plugin_type": "general",
"sdk": { "min_version": "0.2.0" },
"dependencies": []
}
组件装饰器
| 装饰器 | 用途 |
|---|---|
@Route(path, methods=[...]) |
注册 HTTP 路由 |
@Hook(hook_point) |
注册 Host 扩展点 |
@API(name, public=False) |
声明插件 API |
Runner 加载后调用 plugin.get_components() 收集声明。
生命周期
async def on_load(self) -> None: ...
async def on_unload(self) -> None: ...
async def on_config_update(self, scope, config_data, version) -> None: ...
平台扩展(可选)
仅当 plugin_type 为 platform 时需要:
from provider_sdk import ProviderPlugin
from provider_sdk.extensions.platform import PlatformAdapter, Candidate, make_id
class MyPlatform(ProviderPlugin, PlatformAdapter):
@property
def name(self) -> str:
return "my_platform"
# init / candidates / complete / close ...
Host 集成
from provider_sdk.runtime import PluginManager
mgr = PluginManager()
await mgr.load_all(Path("plugins"), session)
routes = mgr.get_components("route")
adapters = mgr.get_platform_adapters() # 仅 platform 插件
仅加载平台插件并注册适配器:
from provider_sdk.integrate import load_platform_plugins, register_platform_adapters
loaded = await load_platform_plugins(Path("plugins"), session)
register_platform_adapters(registry, loaded)
示例
examples/hello_plugin/— 通用插件(Route/Hook/API)examples/echo_platform/— 平台扩展
pytest -q
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file provider_sdk-0.3.5.tar.gz.
File metadata
- Download URL: provider_sdk-0.3.5.tar.gz
- Upload date:
- Size: 26.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e665c0071af7728cdf2b0fc3758332341705fbf40de9093603d4f1fe353dedf
|
|
| MD5 |
4c6e55233f7dec428a194f369da9ddff
|
|
| BLAKE2b-256 |
73c4edb4af953e7d0cb26cb9fb57cde5ac2b86ce808b6173154ba5bb224ae104
|
File details
Details for the file provider_sdk-0.3.5-py3-none-any.whl.
File metadata
- Download URL: provider_sdk-0.3.5-py3-none-any.whl
- Upload date:
- Size: 31.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2fcd52872295a7f181920b53145bfcafe1dc1633a1aac3c724fd1dc35a2b6ce4
|
|
| MD5 |
6766fe5ff2eca83d35aad6b91c04aa83
|
|
| BLAKE2b-256 |
af1151a89773fe4f8882b7c0232f4ba89ab84bf0dbd074633cfa878265d1799c
|