dify-api-client


Namedify-api-client JSON
Version 0.0.14 PyPI version JSON
download
home_pageNone
Summarydify-api-client - A package for interacting with the Dify Service-API
upload_time2025-08-14 03:43:49
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseMIT 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.
keywords dify-api dify-client
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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
```
- Export python path to run dev
```
export PYTHONPATH=.
```
            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "dify-api-client",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "dify-api, dify-client",
    "author": null,
    "author_email": "lucas <lucas@castalk.com>",
    "download_url": "https://files.pythonhosted.org/packages/17/43/a48252a1c154b38b71bf1abfb5804961dd37aeee1cba39a4b9e65ef961c6/dify_api_client-0.0.14.tar.gz",
    "platform": null,
    "description": "# dify-api-client\n\nThis package is a fork of [`dify-client-python`](https://github.com/haoyuhu/dify-client-python) with custom modifications\n\nIt provides a convenient and powerful interface to interact with the Dify API, supporting both synchronous and asynchronous operations.\n\n## Main Features\n\n* **Synchronous and Asynchronous Support**: The client offers both synchronous and asynchronous methods, allowing for\n  flexible integration into various Python codebases and frameworks.\n* **Stream and Non-stream Support**: Seamlessly work with both streaming and non-streaming endpoints of the Dify API for\n  real-time and batch processing use cases.\n* **Comprehensive Endpoint Coverage**: Support completion, chat, workflows, feedback, file uploads, etc., the client\n  covers all available Dify API endpoints.\n\n\n## Quick Start\n### Sync \nHere's a quick example of how you can use the `DifyClient` to send a chat message.\n\n```python\nimport uuid\nfrom dify_client import DifyClient, models\n\n# Initialize the client with your API key\nclient = DifyClient(\n    api_key=\"your-api-key\",\n    api_base=\"http://localhost/v1\",\n)\nuser = str(uuid.uuid4())\n\n# Create a blocking chat request\nblocking_chat_req = models.ChatRequest(\n    query=\"Hi, dify-client-python!\",\n    inputs={\"city\": \"Beijing\"},\n    user=user,\n    response_mode=models.ResponseMode.BLOCKING,\n)\n\n# Send the chat message\nchat_response = client.chat_messages(blocking_chat_req, timeout=60.)\nprint(chat_response)\n\n# Create a streaming chat request\nstreaming_chat_req = models.ChatRequest(\n    query=\"Hi, dify-client-python!\",\n    inputs={\"city\": \"Beijing\"},\n    user=user,\n    response_mode=models.ResponseMode.STREAMING,\n)\n\n# Send the chat message\nfor chunk in client.chat_messages(streaming_chat_req, timeout=60.):\n    print(chunk)\n```\n\n### Async\nFor asynchronous operations, use the `AsyncDifyClient` in a similar fashion:\n\n```python\nimport asyncio\nimport uuid\n\nfrom dify_client import AsyncDifyClient, models\n# Initialize the async client with your API key\nasync_client = AsyncDifyClient(\n    api_key=\"your-api-key\",\n    api_base=\"http://localhost/v1\",\n)\n\n\n# Define an asynchronous function to send a blocking chat message with BLOCKING ResponseMode\nasync def send_chat_message():\n    user = str(uuid.uuid4())\n    # Create a blocking chat request\n    blocking_chat_req = models.ChatRequest(\n        query=\"Hi, dify-client-python!\",\n        inputs={\"city\": \"Beijing\"},\n        user=user,\n        response_mode=models.ResponseMode.BLOCKING,\n    )\n    chat_response = await async_client.achat_messages(blocking_chat_req, timeout=60.)\n    print(chat_response)\n\n\n# Define an asynchronous function to send a chat message with STREAMING ResponseMode\nasync def send_chat_message_stream():\n    user = str(uuid.uuid4())\n    # Create a blocking chat request\n    streaming_chat_req = models.ChatRequest(\n        query=\"Hi, dify-client-python!\",\n        inputs={\"city\": \"Beijing\"},\n        user=user,\n        response_mode=models.ResponseMode.STREAMING,\n    )\n    async for chunk in await async_client.achat_messages(streaming_chat_req, timeout=60.):\n        print(chunk)\n\n\n# Run the asynchronous function\nasyncio.gather(send_chat_message(), send_chat_message_stream())\n```\n\n## Development\n- Setup env\n```\nuv sync --extra dev\n```\n- Export python path to run dev\n```\nexport PYTHONPATH=.\n```",
    "bugtrack_url": null,
    "license": "MIT License\n        \n        Copyright (c) 2024 haoyuhu\n        \n        Permission is hereby granted, free of charge, to any person obtaining a copy\n        of this software and associated documentation files (the \"Software\"), to deal\n        in the Software without restriction, including without limitation the rights\n        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n        copies of the Software, and to permit persons to whom the Software is\n        furnished to do so, subject to the following conditions:\n        \n        The above copyright notice and this permission notice shall be included in all\n        copies or substantial portions of the Software.\n        \n        THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n        SOFTWARE.",
    "summary": "dify-api-client - A package for interacting with the Dify Service-API",
    "version": "0.0.14",
    "project_urls": {
        "Homepage": "https://github.com/lucas-castalk/dify-api-client",
        "Source": "https://github.com/lucas-castalk/dify-api-client"
    },
    "split_keywords": [
        "dify-api",
        " dify-client"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "b653fb89c10c759c95c4d7cb668137e61bf855451c20904c09f6659411e66a3a",
                "md5": "fba3792a51c0271022fe7e698e840740",
                "sha256": "d106fb6da08b75694eb37e4706d140e51f20bd577df676b7ea0536359db0659c"
            },
            "downloads": -1,
            "filename": "dify_api_client-0.0.14-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fba3792a51c0271022fe7e698e840740",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 20653,
            "upload_time": "2025-08-14T03:43:47",
            "upload_time_iso_8601": "2025-08-14T03:43:47.870204Z",
            "url": "https://files.pythonhosted.org/packages/b6/53/fb89c10c759c95c4d7cb668137e61bf855451c20904c09f6659411e66a3a/dify_api_client-0.0.14-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "1743a48252a1c154b38b71bf1abfb5804961dd37aeee1cba39a4b9e65ef961c6",
                "md5": "6e85685e10cc7711141d41d2b5aa0024",
                "sha256": "13e42b9f9a33d55a3aa0d0b8df457a456b3d673ae0049457ddf667a7e7a72980"
            },
            "downloads": -1,
            "filename": "dify_api_client-0.0.14.tar.gz",
            "has_sig": false,
            "md5_digest": "6e85685e10cc7711141d41d2b5aa0024",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 79157,
            "upload_time": "2025-08-14T03:43:49",
            "upload_time_iso_8601": "2025-08-14T03:43:49.830149Z",
            "url": "https://files.pythonhosted.org/packages/17/43/a48252a1c154b38b71bf1abfb5804961dd37aeee1cba39a4b9e65ef961c6/dify_api_client-0.0.14.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-14 03:43:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lucas-castalk",
    "github_project": "dify-api-client",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "dify-api-client"
}
        
Elapsed time: 1.05831s