Skip to main content

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/ — 平台扩展插件

文档:docs/guide.md

Developer Guide

Provider 插件开发指南

定位

provider-sdk 是通用插件 SDK,约定包括:

  • 独立包,禁止 import src.*
  • plugin.py + create_plugin() + _manifest.json
  • ProviderPlugin 生命周期 + 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

Metadata

Release files for provider-sdk 0.3.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for provider-sdk 0.3.10
File Size Uploaded
provider_sdk-0.3.10.tar.gz 28.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for provider-sdk 0.3.10
File Interpreter ABI Platform
provider_sdk-0.3.10-py3-none-any.whl Python 3 none any Details

Total release size: 61.3 kB

Release files / provider_sdk-0.3.10.tar.gz

Download URL provider_sdk-0.3.10.tar.gz
Size 28.3 kB
Tags Source
SHA-256 checksum
How to use checksums
3f31e6064736fc8adabbdf04223f181e1236842ad0d9301b6d2b20b91cf39c9f
BLAKE2b-256 checksum
How to use checksums
b73745bb90defa20f01d977b6bf78647801ab88331b7e28fc4ec38934f6ff841
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.15

Release files / provider_sdk-0.3.10-py3-none-any.whl

Download URL provider_sdk-0.3.10-py3-none-any.whl
Size 33.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
20592f0bac26e8fa851a6955f089af9d55d60d892a03a927a97d73f5618ca6a0
BLAKE2b-256 checksum
How to use checksums
9976176d83f48a4e87c55968a3681f7bcf4d09cd052c038b2949ef36cc1c0451
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.15

Release history Release notifications | RSS feed

This release

0.3.10 This release

2 release files

0.3.9

2 release files

0.3.8

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page