Dify Plugin SDK

0.7.4 · active · verified Sat Apr 11

The Dify Plugin SDK allows developers to build custom plugins for the Dify platform. It provides classes and decorators to define plugin metadata, inputs, outputs, and API endpoints, enabling seamless integration with Dify AI applications. Currently at version 0.7.4, the library is under active development with frequent releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a basic Dify plugin with metadata, inputs, outputs, and a single API endpoint. The `plugin.run()` call starts a local server for development and testing, exposing the plugin's OpenAPI specification.

import os
from dify_plugin import DifyPlugin, PluginMetadata, Category, Input, Output

plugin = DifyPlugin(
    metadata=PluginMetadata(
        name="Hello Dify",
        description="A simple plugin that says hello.",
        icon="https://dify.ai/favicon.ico",
        category=Category.TOOLS,
        inputs=[
            Input(name="name", type="string", required=True, description="Your name"),
        ],
        outputs=[
            Output(name="greeting", type="string"),
        ],
    )
)

@plugin.api("hello")
def hello_world_api(name: str):
    return {"greeting": f"Hello, {name}!"}

if __name__ == "__main__":
    # In a real Dify environment, the plugin would be served externally.
    # For local testing, run this script and access at http://127.0.0.1:PORT/.well-known/ai-plugin.json
    plugin.run()

view raw JSON →