Clients
This section describes the client classes available in the Dify client library.
Basic Usage
Here are some common operations with the Dify client:
from dify_user_client import DifyClient, Credentials, AppType
# Initialize client
credentials = Credentials(username="your-email", password="your-password")
client = DifyClient("https://your-dify-instance", credentials)
# Create a new application
new_app = client.create_app(
name="My App",
mode=AppType.chat,
description="A chat application",
icon_type="emoji",
icon="🤖"
)
print(f"Created app with ID: {new_app.id}")
# Get an existing application
existing_app = client.get_app("your-app-id")
print(f"Retrieved app: {existing_app.info['name']}")
# List all applications
all_apps = client.apps
for app in all_apps:
print(f"App: {app.info['name']} (ID: {app.id})")
# Delete an application
client.delete_app("app-to-delete-id")
Base Client
- class DifyBaseClient
Base client class providing core functionality.
- __init__(base_url: str, credentials: Credentials)
Initialize a new client.
- Parameters:
base_url – Base URL of the Dify API
credentials – Authentication credentials
- _login()
Authenticate with the Dify API.
User Client
- class DifyUserClient
Client for user-facing operations.
- property tool_providers list[ToolProvider]
Get all available tool providers.
- get_tool_provider(provider_id: str) ToolProvider
Get a specific tool provider by ID.
- property model_providers list[ModelProvider]
Get all available model providers.
- get_model_provider(provider_id: str) ModelProvider
Get a specific model provider by ID.
Combined Client
- class DifyClient
Combined client providing access to both user and knowledge operations.
- __init__(base_url: str, credentials: Credentials)
Initialize a new combined client.
- Parameters:
base_url – Base URL of the Dify API
credentials – Authentication credentials
- Variables:
knowledge – Instance of
DifyKnowledgeClient
for knowledge operations
Data Models
- class Credentials
Authentication credentials.
- username: str
Username or email
- password: str
Password