Skip to main content

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

文档: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_typeplatform 时需要:

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

provider_sdk-0.3.8.tar.gz (28.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

provider_sdk-0.3.8-py3-none-any.whl (33.0 kB view details)

Uploaded Python 3

File details

Details for the file provider_sdk-0.3.8.tar.gz.

File metadata

  • Download URL: provider_sdk-0.3.8.tar.gz
  • Upload date:
  • Size: 28.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for provider_sdk-0.3.8.tar.gz
Algorithm Hash digest
SHA256 27dca8d763a82db726014aedc0644a412cb5645306071bf7a7c6f14b0ba4520b
MD5 727572e9f2abfc25e8745633beb60ca5
BLAKE2b-256 9be96cafae6a344a5d574fd8b04966ce2358affe605137480da1ab93ec32a52b

See more details on using hashes here.

File details

Details for the file provider_sdk-0.3.8-py3-none-any.whl.

File metadata

  • Download URL: provider_sdk-0.3.8-py3-none-any.whl
  • Upload date:
  • Size: 33.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for provider_sdk-0.3.8-py3-none-any.whl
Algorithm Hash digest
SHA256 5b2de432178851d248ceec3275be7ff67f92c50e6067deabd15b5196edf59cc1
MD5 f728e63ae28023c3cca4d3e267c7d30f
BLAKE2b-256 72e0da55e072312d2a4668a6eb35b9e73f4fb27258e554466b719ba5d613c7ef

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page