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.

_send_user_request(method: str, url: str, **kwargs)

Send an authenticated request to the API.

Parameters:
  • method – HTTP method

  • url – API endpoint URL

  • kwargs – Additional request parameters

User Client

class DifyUserClient

Client for user-facing operations.

update_timezone(timezone: str = 'Europe/Moscow')

Update user timezone setting.

update_system_model(model_settings: list[dict])

Update system model settings.

property apps list[App]

Get all available applications.

get_app(app_id: str) App

Get a specific application by ID.

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 tools list[Tool]

Get all available tools.

get_tool(name: str) Tool

Get a specific tool by name.

property model_providers list[ModelProvider]

Get all available model providers.

get_model_provider(provider_id: str) ModelProvider

Get a specific model provider by ID.

create_app(name: str, mode: AppType, description: str = '', icon_type: Literal['emoji', 'image'] = 'emoji', icon: str = '🤖', icon_background: str = '#FFEAD5') App

Create a new application.

create_app_from_yaml(yaml_content: str) App

Create a new application from YAML configuration.

delete_app(app_id: str)

Delete an application.

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