Metadata-Version: 2.4
Name: dify-api-client
Version: 0.0.7
Summary: dify-api-client - A package for interacting with the Dify Service-API
Project-URL: Homepage, https://github.com/lucas-castalk/dify-api-client
Project-URL: Source, https://github.com/lucas-castalk/dify-api-client
Author-email: lucas <lucas@castalk.com>
License: MIT License
        
        Copyright (c) 2024 haoyuhu
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE.md
Keywords: dify-api,dify-client
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.10
Requires-Dist: dotenv>=0.9.9
Requires-Dist: httpx-sse>=0.4.0
Requires-Dist: httpx>=0.28.1
Requires-Dist: pydantic>=2.10.4
Provides-Extra: dev
Requires-Dist: pre-commit; extra == 'dev'
Requires-Dist: pylint; extra == 'dev'
Requires-Dist: pytest; extra == 'dev'
Requires-Dist: ruff>=0.11.13; extra == 'dev'
Description-Content-Type: text/markdown

# dify-api-client

This package is a fork of [`dify-client-python`](https://github.com/haoyuhu/dify-client-python) with custom modifications

It provides a convenient and powerful interface to interact with the Dify API, supporting both synchronous and asynchronous operations.

## Main Features

* **Synchronous and Asynchronous Support**: The client offers both synchronous and asynchronous methods, allowing for
  flexible integration into various Python codebases and frameworks.
* **Stream and Non-stream Support**: Seamlessly work with both streaming and non-streaming endpoints of the Dify API for
  real-time and batch processing use cases.
* **Comprehensive Endpoint Coverage**: Support completion, chat, workflows, feedback, file uploads, etc., the client
  covers all available Dify API endpoints.


## Quick Start
### Sync 
Here's a quick example of how you can use the `DifyClient` to send a chat message.

```python
import uuid
from dify_client import DifyClient, models

# Initialize the client with your API key
client = DifyClient(
    api_key="your-api-key",
    api_base="http://localhost/v1",
)
user = str(uuid.uuid4())

# Create a blocking chat request
blocking_chat_req = models.ChatRequest(
    query="Hi, dify-client-python!",
    inputs={"city": "Beijing"},
    user=user,
    response_mode=models.ResponseMode.BLOCKING,
)

# Send the chat message
chat_response = client.chat_messages(blocking_chat_req, timeout=60.)
print(chat_response)

# Create a streaming chat request
streaming_chat_req = models.ChatRequest(
    query="Hi, dify-client-python!",
    inputs={"city": "Beijing"},
    user=user,
    response_mode=models.ResponseMode.STREAMING,
)

# Send the chat message
for chunk in client.chat_messages(streaming_chat_req, timeout=60.):
    print(chunk)
```

### Async
For asynchronous operations, use the `AsyncDifyClient` in a similar fashion:

```python
import asyncio
import uuid

from dify_client import AsyncDifyClient, models
# Initialize the async client with your API key
async_client = AsyncDifyClient(
    api_key="your-api-key",
    api_base="http://localhost/v1",
)


# Define an asynchronous function to send a blocking chat message with BLOCKING ResponseMode
async def send_chat_message():
    user = str(uuid.uuid4())
    # Create a blocking chat request
    blocking_chat_req = models.ChatRequest(
        query="Hi, dify-client-python!",
        inputs={"city": "Beijing"},
        user=user,
        response_mode=models.ResponseMode.BLOCKING,
    )
    chat_response = await async_client.achat_messages(blocking_chat_req, timeout=60.)
    print(chat_response)


# Define an asynchronous function to send a chat message with STREAMING ResponseMode
async def send_chat_message_stream():
    user = str(uuid.uuid4())
    # Create a blocking chat request
    streaming_chat_req = models.ChatRequest(
        query="Hi, dify-client-python!",
        inputs={"city": "Beijing"},
        user=user,
        response_mode=models.ResponseMode.STREAMING,
    )
    async for chunk in await async_client.achat_messages(streaming_chat_req, timeout=60.):
        print(chunk)


# Run the asynchronous function
asyncio.gather(send_chat_message(), send_chat_message_stream())
```

## Development
- Setup env
```
uv sync --extra dev
```